Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Images in a Usercontrol

Images in a Usercontrol

Scheduled Pinned Locked Moved Visual Basic
graphicshardwarequestion
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tibmark
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • T tibmark

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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++

      T 1 Reply Last reply
      0
      • C Christian Graus

        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++

        T Offline
        T Offline
        tibmark
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • T tibmark

          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

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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++

          T 1 Reply Last reply
          0
          • C Christian Graus

            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++

            T Offline
            T Offline
            tibmark
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • T tibmark

              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

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Easiest approach - why not just load the files from disc ? Christian Graus - Microsoft MVP - C++

              T 1 Reply Last reply
              0
              • C Christian Graus

                Easiest approach - why not just load the files from disc ? Christian Graus - Microsoft MVP - C++

                T Offline
                T Offline
                tibmark
                wrote on last edited by
                #7

                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

                C R 2 Replies Last reply
                0
                • T tibmark

                  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

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  http://www.codeproject.com/useritems/ReflectionXml.asp[^] I think this answers your question. Christian Graus - Microsoft MVP - C++

                  T 1 Reply Last reply
                  0
                  • C Christian Graus

                    http://www.codeproject.com/useritems/ReflectionXml.asp[^] I think this answers your question. Christian Graus - Microsoft MVP - C++

                    T Offline
                    T Offline
                    tibmark
                    wrote on last edited by
                    #9

                    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

                    C 1 Reply Last reply
                    0
                    • T tibmark

                      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

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #10

                      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++

                      1 Reply Last reply
                      0
                      • T tibmark

                        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

                        R Offline
                        R Offline
                        rswipe
                        wrote on last edited by
                        #11

                        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.

                        T 1 Reply Last reply
                        0
                        • R rswipe

                          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.

                          T Offline
                          T Offline
                          tibmark
                          wrote on last edited by
                          #12

                          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

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups