hrabia Posted October 5, 2005 Posted October 5, 2005 I've some embedded images in my app. I load them dynamically at run-time: Assembly assembly = Assembly.GetExecutingAssembly(); string assemblyName = Assembly.GetExecutingAssembly().GetName().Name.ToString(); Stream stream = assembly.GetManifestResourceStream(assemblyName + ".Images.ARROWDN.BMP"); this.butBottom.Image = Image.FromStream(stream); I've no idea how I can do this at design-time. Help :) ? Adam Quote A man and a dog have an average of three legs. Beaware of Statistics.
Leaders snarfblam Posted October 5, 2005 Leaders Posted October 5, 2005 What do you want to do with them at design time? If you use an image as a property on a control then the code to do this is generated for you. If not, then I don't understand what could be done for you at design time. Perhaps an ImageList component would make your life easier. This will embed the images for you and you can pull them up at run-time by index with a single line of code. If I am making an app with a lot of embedded images, I always make a function that accepts the image's pre-compile filename and loads the image for me. [Vb] Public Shared Function GetEmbeddedImage(Name As String) As Image\ Dim Assm As Assembly = Assembly.GetExecutingAssembly() Dim AssmName As String = Assm.GetName().Name Dim Stream As Stream = Assm.GetManifestResourceStream(AssmName & "." & Name); Return Image.FromStream(Stream) End Sub [/code] Quote [sIGPIC]e[/sIGPIC]
*Experts* DiverDan Posted October 5, 2005 *Experts* Posted October 5, 2005 You need to build a user control the inherits the control that you want this functionallity. Paint the image to the control in the user control's Overrides OnPaint sub. Although I've never tried this with embedded images I don't think there should be any problems. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
hrabia Posted October 6, 2005 Author Posted October 6, 2005 (edited) marble_eater - it's simple, I'd like to see my button images in the designer. At the moment my buttons are all blank. I can reference an image using path to a file to see the image in designer, but how to do this with an embedded image (withaut referencing the file)? Thanks DiverDan, that was my idea also, but how to change an image for different buttons? Edited October 6, 2005 by hrabia Quote A man and a dog have an average of three legs. Beaware of Statistics.
*Experts* DiverDan Posted October 6, 2005 *Experts* Posted October 6, 2005 I wish I had more time to knock up a sample for you as it's not that complicated. Not getting very deep into details, I think you'll only need to over ride the OnPaint sub and paint the image and text into the button. Also, you'll be able to customize the button borders, gradients, mouse enter & leave effects and a bunch more in only a couple of hours work. I have a few examples of my inherited button controls. If you're interested drop me a PM and I'll email some to you. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
georgepatotk Posted October 6, 2005 Posted October 6, 2005 hrabia, as what marble_eater said, use an imagelist would make ur life easier. Just add all the images into the image list, then, u could call out the image in the design time. So, if you are calling an embedded image, you could call by using the path like "Images/abc.jpg" if you are putting in under the Images folder. And if you are putting it in the Project root folder, you could just call like "abc.jpg". I used to do this few months ago. If not mistaken, this is the way i used. Hope this help Quote George C.K. Low
hrabia Posted October 6, 2005 Author Posted October 6, 2005 Thanks georgepatotk. The idea with imagelist works very well but... ...is it really the one and only way "to see" images at design- and run-time without big effort? Hmm... thanks anyway to you all! Quote A man and a dog have an average of three legs. Beaware of Statistics.
*Experts* DiverDan Posted October 6, 2005 *Experts* Posted October 6, 2005 I've got another thought hrabia. If the embedded images are only used for the buttons, then you can easily embed them in the inherited button control instead of the project. This would help speed up the painting, increase flexibility and reduce complexity. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Leaders dynamic_sysop Posted October 6, 2005 Leaders Posted October 6, 2005 just do it inside the constructor of the form, like the highlighted ( BOLD ) part below ... #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(16, 16) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 0 Me.Button1.Text = "Button1" [b] '/// like this ... Dim btnimg As Image = Image.FromStream(Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(Application.ProductName & ".Picture1.jpg"))[/b] [b] '/// SET IMAGE ON BUTTON ....[/b][b] Me.Button1.Image = btnimg[/b] ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(432, 230) Me.Controls.Add(Me.Button1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region [size=2] [/size] Quote
Leaders snarfblam Posted October 7, 2005 Leaders Posted October 7, 2005 I should apologize. I kinda... missed the title of the thread and I thought that you were simply asking about embedded images. Sorry for the not very useful answer. Quote [sIGPIC]e[/sIGPIC]
Diesel Posted October 7, 2005 Posted October 7, 2005 @Dynamic: Won't the designer overwrite that the next time it serializes the form? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.