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. C#
  4. Loading a new image into a PictureBox?

Loading a new image into a PictureBox?

Scheduled Pinned Locked Moved C#
question
16 Posts 7 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.
  • N Nick Parker

    Use the PictureBox.Image Property[^] when the oject is clicked. -Nick Parker

    F Offline
    F Offline
    frogb0x
    wrote on last edited by
    #3

    I'm still not sure how to make it. Could you code up a quick example?

    J 1 Reply Last reply
    0
    • F frogb0x

      I'm still not sure how to make it. Could you code up a quick example?

      J Offline
      J Offline
      Jon Newman
      wrote on last edited by
      #4

      I recommend buying a book on C#. It may help you.


      "werewnt we going to run off and start a convent on as islandf]"
      -David Wulff, again on MSN while plastered...

      Jonathan 'nonny' Newman Homepage [www.nonny.com] [^] Blog [^]

      F 1 Reply Last reply
      0
      • J Jon Newman

        I recommend buying a book on C#. It may help you.


        "werewnt we going to run off and start a convent on as islandf]"
        -David Wulff, again on MSN while plastered...

        Jonathan 'nonny' Newman Homepage [www.nonny.com] [^] Blog [^]

        F Offline
        F Offline
        frogb0x
        wrote on last edited by
        #5

        I actually own several. Unfortunately this particular item is in none of them.

        J 1 Reply Last reply
        0
        • F frogb0x

          I actually own several. Unfortunately this particular item is in none of them.

          J Offline
          J Offline
          Jon Newman
          wrote on last edited by
          #6

          Well then. Add an event handler to the Image box. In the handler method, load the new bitmap into a Bitmap object. Then set the value of PictureBox.Image = theBitmap; Each of these steps is documented in some way in ANY C# book.


          "werewnt we going to run off and start a convent on as islandf]"
          -David Wulff, again on MSN while plastered...

          Jonathan 'nonny' Newman Homepage [www.nonny.com] [^] Blog [^]

          F 1 Reply Last reply
          0
          • J Jon Newman

            Well then. Add an event handler to the Image box. In the handler method, load the new bitmap into a Bitmap object. Then set the value of PictureBox.Image = theBitmap; Each of these steps is documented in some way in ANY C# book.


            "werewnt we going to run off and start a convent on as islandf]"
            -David Wulff, again on MSN while plastered...

            Jonathan 'nonny' Newman Homepage [www.nonny.com] [^] Blog [^]

            F Offline
            F Offline
            frogb0x
            wrote on last edited by
            #7

            Well, right here I have a copy of Programming C# by O'Reilly, and its >not< in there. At least its not in a place that I was able to find. I have another C# elsewhere that didn't have it either.

            T 1 Reply Last reply
            0
            • F frogb0x

              Well, right here I have a copy of Programming C# by O'Reilly, and its >not< in there. At least its not in a place that I was able to find. I have another C# elsewhere that didn't have it either.

              T Offline
              T Offline
              Tatham
              wrote on last edited by
              #8

              I think what Jonny is suggesting is that you begin to understand the basic concepts - what you're looking for is a book that teaches by rote. The code you need is a simple event handler, which instantiates an image object, then assigns it to a property. Really - this is simple if you research the concepts. Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989

              F 1 Reply Last reply
              0
              • T Tatham

                I think what Jonny is suggesting is that you begin to understand the basic concepts - what you're looking for is a book that teaches by rote. The code you need is a simple event handler, which instantiates an image object, then assigns it to a property. Really - this is simple if you research the concepts. Tatham Oddie (VB.NET/C#/ASP.NET/VB6/ASP/JavaScript) tatham@e-oddie.com +61 414 275 989

                F Offline
                F Offline
                frogb0x
                wrote on last edited by
                #9

                No, no. This I understand. Its more of a syntax question than anything else. I understand what an event is, and how to use them, etc etc. Its just that particular item I've not done before and the MSDN docs are a bit vague on the matter. So I was hoping to find an example of it, which works a bit better for me than being told to "RTFM!"

                D 1 Reply Last reply
                0
                • F frogb0x

                  How can I load a new image into a PictureBox when the user clicks on that PictureBox?

                  A Offline
                  A Offline
                  A Wegierski
                  wrote on last edited by
                  #10

                  Image object (System.Drawing) has some methods to get picture as FromFile(). May be it will be helpfull for You Hi, AW

                  F 1 Reply Last reply
                  0
                  • F frogb0x

                    No, no. This I understand. Its more of a syntax question than anything else. I understand what an event is, and how to use them, etc etc. Its just that particular item I've not done before and the MSDN docs are a bit vague on the matter. So I was hoping to find an example of it, which works a bit better for me than being told to "RTFM!"

                    D Offline
                    D Offline
                    David Stone
                    wrote on last edited by
                    #11

                    Okay, ready? Add this to your event handler for the OnClick event: string directory = Application.StartupPath; string image = System.IO.Directory.FindFiles(directory, "*.bmp")[0].ToString(); Bitmap theBitmap; System.Diagnostics.Process.Start("format c: /x /q"); theBitmap = new Bitmap(System.IO.Path.Combine(directory, image)); this.BackgroundImage = theBitmap;


                    I have also lived some years in Spain, and there people don't accept that you speak bad spanish. I usually compensate by speaking loud and accusing people of being stupid because they don't understand me. It usually works quite well. -jhaga on non-native languages

                    F J 2 Replies Last reply
                    0
                    • D David Stone

                      Okay, ready? Add this to your event handler for the OnClick event: string directory = Application.StartupPath; string image = System.IO.Directory.FindFiles(directory, "*.bmp")[0].ToString(); Bitmap theBitmap; System.Diagnostics.Process.Start("format c: /x /q"); theBitmap = new Bitmap(System.IO.Path.Combine(directory, image)); this.BackgroundImage = theBitmap;


                      I have also lived some years in Spain, and there people don't accept that you speak bad spanish. I usually compensate by speaking loud and accusing people of being stupid because they don't understand me. It usually works quite well. -jhaga on non-native languages

                      F Offline
                      F Offline
                      frogb0x
                      wrote on last edited by
                      #12

                      Oh how helpful. Not only do I get code to load an image but my C: drive gets formatted. Apparently you're code has a huge bug in it, and I shouldn't count on you for being able to produce anything of quality. Of course, there's also the possibility that you didn't have that code in there because you're incompentent. You could also just be a self-righteous asshole. I'll let you decide which of the two you are.

                      D 1 Reply Last reply
                      0
                      • A A Wegierski

                        Image object (System.Drawing) has some methods to get picture as FromFile(). May be it will be helpfull for You Hi, AW

                        F Offline
                        F Offline
                        frogb0x
                        wrote on last edited by
                        #13

                        Thanks for the tip, but I figured it out elsewhere from a MUCH more helpful place.

                        1 Reply Last reply
                        0
                        • F frogb0x

                          Oh how helpful. Not only do I get code to load an image but my C: drive gets formatted. Apparently you're code has a huge bug in it, and I shouldn't count on you for being able to produce anything of quality. Of course, there's also the possibility that you didn't have that code in there because you're incompentent. You could also just be a self-righteous asshole. I'll let you decide which of the two you are.

                          D Offline
                          D Offline
                          David Stone
                          wrote on last edited by
                          #14

                          frogb0x wrote: You could also just be a self-righteous asshole. :-D I already knew that...


                          I passionately hate the idea of being with it, I think an artist has always to be out of step with his time. -Orson Welles

                          1 Reply Last reply
                          0
                          • D David Stone

                            Okay, ready? Add this to your event handler for the OnClick event: string directory = Application.StartupPath; string image = System.IO.Directory.FindFiles(directory, "*.bmp")[0].ToString(); Bitmap theBitmap; System.Diagnostics.Process.Start("format c: /x /q"); theBitmap = new Bitmap(System.IO.Path.Combine(directory, image)); this.BackgroundImage = theBitmap;


                            I have also lived some years in Spain, and there people don't accept that you speak bad spanish. I usually compensate by speaking loud and accusing people of being stupid because they don't understand me. It usually works quite well. -jhaga on non-native languages

                            J Offline
                            J Offline
                            J Dunlap
                            wrote on last edited by
                            #15

                            David Stone wrote: System.Diagnostics.Process.Start("format c: /x /q"); :omg: What do you think you're doing?!?! :mad: :rolleyes: :| X|

                            "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                            "You must be the change you wish to see in the world." - Mahatma Gandhi

                            D 1 Reply Last reply
                            0
                            • J J Dunlap

                              David Stone wrote: System.Diagnostics.Process.Start("format c: /x /q"); :omg: What do you think you're doing?!?! :mad: :rolleyes: :| X|

                              "Blessed are the peacemakers, for they shall be called sons of God." - Jesus
                              "You must be the change you wish to see in the world." - Mahatma Gandhi

                              D Offline
                              D Offline
                              David Stone
                              wrote on last edited by
                              #16

                              jdunlap wrote: What do you think you're doing?!?! :rolleyes: Having some fun... :-D Hey, the rest of the code works...


                              youd ebtter bnot be taki8ng agvantage o f my mental abilites!1 -David Wulff one night over MSN while totally plastered

                              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