On resize of Form1, refresh PictureBox1?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spaceyavin
    New Member
    • Jun 2010
    • 4

    On resize of Form1, refresh PictureBox1?

    A while back I downloaded a Webcam C# project and for I have worked on it for a bit. It uses a PictureBox which shows the image received from the webcam and changes itself. What I'd like to know is how to make the image refresh it's self on the Form's resize, because at the moment it continues to show it in the size of the previous size until I manually refresh. Please help me by giving me a code sample using the SizeChanged event. I already have the refresh code. I ONLY need the event in a working condition.

    Thanks!

    P.S. The attached picture shows the problem. Certain words and logos have been hidden to protect against privacy and copyright infringement.
    Attached Files
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    There's a ResizeEnd event, try attaching to that. It will fire when your form is finished resizing, and in there you can make whatever call you'd make when you click your button for a manual refresh.

    Comment

    • Spaceyavin
      New Member
      • Jun 2010
      • 4

      #3
      Could you give me an example of this event? I'm not too good at C# so could you show a sample of usage?

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        It's easy enough to create a sample yourself...

        1. Create a new project in VS
        2. On the Form's events list, look for ResizeEnd, double click it to create an event.
        3. In the code for the event that was just generated, put the following: Console.WriteLi ne("Form.Resize End event fired!");
        (NOTE: You may wish to use a MessageBox.Show (...) call here if you can't access the output window for whatever reason)
        4. Run the project
        5. Click/drag to resize the form
        6. Release the click

        You should see the event fire. Once you understand this, replace the code in the event with whatever you like.

        Comment

        • Spaceyavin
          New Member
          • Jun 2010
          • 4

          #5
          Uh, where's the "event list"? I've searched high and low. For reference, I use Microsoft Visual C# 2010 Express.

          Comment

          • GaryTexmo
            Recognized Expert Top Contributor
            • Jul 2009
            • 1501

            #6
            Please refer to the image. You can either use the GUI interface to get to the events by clicking the lightning bolt in the properties pain (see image) or you can add the event manually via code (say, in your constructor).

            Code:
            this.ResizeEnd += new EventHandler(SomeMethod);
            
            ...
            
            void SomeMethod(object sender, EventArgs e) { ... }
            Were you not able to find this, or are you unsure of how to attach to events?

            *Edit: Oh that came out horribly small... let me know if you can't figure it out from that and I'll try to make a bigger one.
            Attached Files

            Comment

            • Spaceyavin
              New Member
              • Jun 2010
              • 4

              #7
              I've got the resize to work. :D

              Thanks for your fantastic help!
              -Spaceyavin

              Comment

              • GaryTexmo
                Recognized Expert Top Contributor
                • Jul 2009
                • 1501

                #8
                You're most welcome!

                Comment

                Working...