Images in a Usercontrol
-
I am trying to develop a new usercontrol that has a default image I need to load. I have an embedded bitmap and using the following code to retrieve it. Dim executing_assembly As System.Reflection.Assembly = Me.GetType.Assembly.GetEntryAssembly() ' Get our namespace. Dim my_namespace As String = executing_assembly.GetName().Name.ToString() ' Load three pictures. Dim picture_stream As Stream Dim bm As Bitmap picture_stream = executing_assembly.GetManifestResourceStream(my_namespace + ".Checked.bmp") If Not (picture_stream Is Nothing) Then bm = New Bitmap(picture_stream) picturebox.Image = bm picture_stream.Close() End If When i reference my control(dll) and try to use it in another app. it does not work all i get is Object Reference not set to an instance of an object. But when i use the code by its self in another project it works. What it boils down to is how can i store/embed an image in a usercontrol dll. Thanks in advance. Mark Thibodeaux
-
I am trying to develop a new usercontrol that has a default image I need to load. I have an embedded bitmap and using the following code to retrieve it. Dim executing_assembly As System.Reflection.Assembly = Me.GetType.Assembly.GetEntryAssembly() ' Get our namespace. Dim my_namespace As String = executing_assembly.GetName().Name.ToString() ' Load three pictures. Dim picture_stream As Stream Dim bm As Bitmap picture_stream = executing_assembly.GetManifestResourceStream(my_namespace + ".Checked.bmp") If Not (picture_stream Is Nothing) Then bm = New Bitmap(picture_stream) picturebox.Image = bm picture_stream.Close() End If When i reference my control(dll) and try to use it in another app. it does not work all i get is Object Reference not set to an instance of an object. But when i use the code by its self in another project it works. What it boils down to is how can i store/embed an image in a usercontrol dll. Thanks in advance. Mark Thibodeaux
tibmark wrote: Dim my_namespace As String = executing_assembly.GetName().Name.ToString() The executing assembly is not the same as the dll, if the code is in a dll. You'll need to get the name that's required for your dll, either by a different method, or by hard coding it. Christian Graus - Microsoft MVP - C++
-
tibmark wrote: Dim my_namespace As String = executing_assembly.GetName().Name.ToString() The executing assembly is not the same as the dll, if the code is in a dll. You'll need to get the name that's required for your dll, either by a different method, or by hard coding it. Christian Graus - Microsoft MVP - C++
-
I was wrong it comes back null is not a valid vaue for stream. i am fairly new to the creation of usercontrols any examples would be very helpful. Mark Thibodeaux
Usercontrols have nothing to do with it. You've obviously copy and pasted this code, do you have any idea what it does ? Resources are stored in your file and retrieved using a fully qualified name. You're building the name by asking what the name of the application that is running is, but that's not the name being used in your dll, which has a different name. Have a look at the string that's being generated, and then replace the application name with the dll name, that should work. I've never pulled resources from a dll before, but I'd imagine that would be the way forward. Christian Graus - Microsoft MVP - C++
-
Usercontrols have nothing to do with it. You've obviously copy and pasted this code, do you have any idea what it does ? Resources are stored in your file and retrieved using a fully qualified name. You're building the name by asking what the name of the application that is running is, but that's not the name being used in your dll, which has a different name. Have a look at the string that's being generated, and then replace the application name with the dll name, that should work. I've never pulled resources from a dll before, but I'd imagine that would be the way forward. Christian Graus - Microsoft MVP - C++
Yes that is what i did, i couldnt find the rigght info just code. So let me ask the question the right way i would like to make a usercontrol that hosts a few bitmap images. what is the best way to do this or can you point me in the right direction. I am doing what i can to learn on limited resources and no real experience. Mark Thibodeaux
-
Yes that is what i did, i couldnt find the rigght info just code. So let me ask the question the right way i would like to make a usercontrol that hosts a few bitmap images. what is the best way to do this or can you point me in the right direction. I am doing what i can to learn on limited resources and no real experience. Mark Thibodeaux
Easiest approach - why not just load the files from disc ? Christian Graus - Microsoft MVP - C++
-
Easiest approach - why not just load the files from disc ? Christian Graus - Microsoft MVP - C++
-
i'm not looking for the easy way out. i want the images to load when i use the control on any app. Mark Thibodeaux
http://www.codeproject.com/useritems/ReflectionXml.asp[^] I think this answers your question. Christian Graus - Microsoft MVP - C++
-
http://www.codeproject.com/useritems/ReflectionXml.asp[^] I think this answers your question. Christian Graus - Microsoft MVP - C++
-
I think this will help. I understand what you were talking about. Thank you for your patience and help. I need all that I can get. By the way any tips to gaining knowledge and experience would be very appreciated. Thanks again. Mark Thibodeaux
tibmark wrote: Thank you for your patience and help. To be honest, I was just thinking that I've been neither patient, nor helpful :-) Normally, I'd whip up a project to work out the definitive answer, but I'm under a little schedule pressure today, and still trying to keep my batting average up. tibmark wrote: By the way any tips to gaining knowledge and experience would be very appreciated. What's worked for me is to always learn why things do what they do, find a code sample and then use MSDN to nut it out, ask lots of questions in places like this one, and invest in good books, which I read at least twice. I nearly fell over today, I was away sick and some orders come in, I got two books, both over 800 pages, and one > 1000. I had no idea they were so big ( they are both ASP.NET, one on security and one on improving performance ). I've got a lot of reading to do.... Christian Graus - Microsoft MVP - C++
-
i'm not looking for the easy way out. i want the images to load when i use the control on any app. Mark Thibodeaux
-
Don't know if 've understoog your application but why don't you use an Imagelist to store and load images. It's easy to access and use.
i want to make a custom checkbox that uses several predefined bitmaps. how and where do i store the images and call them. i want to be able to use in any project. i have come close but the project i want to use it in has to be add to the usercontrol solution or it will not work. Mark Thibodeaux