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. Zooming picturebox not updating

Zooming picturebox not updating

Scheduled Pinned Locked Moved C#
helpgraphicsalgorithms
6 Posts 4 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.
  • J Offline
    J Offline
    jisan22
    wrote on last edited by
    #1

    Hi, I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size. The picture box is called myPictureBox and has a size of 70,100 at the beginning.

    private void button1_Click(object sender, EventArgs e)
    {
    for (int j = 0; j < 5; j++)
    {
    zoomOutPicture((j + 1) * 10);
    System.Threading.Thread.Sleep(1000);
    }
    }

    private void zoomOutPicture(int zoomF)
    {
    int myHeight = 100+zoomF;
    int myWith = 70 + (int)Math.Round(zoomF * .7, 0);

      System.Drawing.Size test;
      test = new System.Drawing.Size(myWith, myHeight);
      myPictureBox.Size = test;
    

    }

    I have spent the last 3 hours searching with out any luck so any help is greatly apriciated. Thank you.

    D F L 3 Replies Last reply
    0
    • J jisan22

      Hi, I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size. The picture box is called myPictureBox and has a size of 70,100 at the beginning.

      private void button1_Click(object sender, EventArgs e)
      {
      for (int j = 0; j < 5; j++)
      {
      zoomOutPicture((j + 1) * 10);
      System.Threading.Thread.Sleep(1000);
      }
      }

      private void zoomOutPicture(int zoomF)
      {
      int myHeight = 100+zoomF;
      int myWith = 70 + (int)Math.Round(zoomF * .7, 0);

        System.Drawing.Size test;
        test = new System.Drawing.Size(myWith, myHeight);
        myPictureBox.Size = test;
      

      }

      I have spent the last 3 hours searching with out any luck so any help is greatly apriciated. Thank you.

      D Offline
      D Offline
      DavidKiryazi
      wrote on last edited by
      #2

      Hi, I tried your code on my machine .Net 2.0 vs2005 and it seems to work fine. I added a line that refreshes the form so maybe try this and see if the results are any different.

      private void button1_Click(object sender, EventArgs e)
      {
      for (int j = 0; j < 5; j++)
      {
      zoomOutPicture((j + 1) * 10);
      this.Refresh(); // <---- line added that references the form with the picture box on it
      System.Threading.Thread.Sleep(1000);
      }
      }

      Dave

      J 1 Reply Last reply
      0
      • J jisan22

        Hi, I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size. The picture box is called myPictureBox and has a size of 70,100 at the beginning.

        private void button1_Click(object sender, EventArgs e)
        {
        for (int j = 0; j < 5; j++)
        {
        zoomOutPicture((j + 1) * 10);
        System.Threading.Thread.Sleep(1000);
        }
        }

        private void zoomOutPicture(int zoomF)
        {
        int myHeight = 100+zoomF;
        int myWith = 70 + (int)Math.Round(zoomF * .7, 0);

          System.Drawing.Size test;
          test = new System.Drawing.Size(myWith, myHeight);
          myPictureBox.Size = test;
        

        }

        I have spent the last 3 hours searching with out any luck so any help is greatly apriciated. Thank you.

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

        Try:

        myPictureBox.Size = test;
        myPictureBox.Refresh();

        My failometer has shot off the end of the scale! I seem to have misplaced my ban button.. no wait... found it!

        1 Reply Last reply
        0
        • J jisan22

          Hi, I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size. The picture box is called myPictureBox and has a size of 70,100 at the beginning.

          private void button1_Click(object sender, EventArgs e)
          {
          for (int j = 0; j < 5; j++)
          {
          zoomOutPicture((j + 1) * 10);
          System.Threading.Thread.Sleep(1000);
          }
          }

          private void zoomOutPicture(int zoomF)
          {
          int myHeight = 100+zoomF;
          int myWith = 70 + (int)Math.Round(zoomF * .7, 0);

            System.Drawing.Size test;
            test = new System.Drawing.Size(myWith, myHeight);
            myPictureBox.Size = test;
          

          }

          I have spent the last 3 hours searching with out any luck so any help is greatly apriciated. Thank you.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          you could "solve" it with some Invalidate() or Refresh() calls, but your approach is fundamentally flawed, since you are blocking the GUI thread for the entire duration of this action, making moving, resizing, e.a. impossible. The correct approach is by using either a separate thread or a timer; since the actions involve Controls, which need to be handled on the main thread anyway, your best option is to start a Windows.Forms.Timer :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


          J 1 Reply Last reply
          0
          • D DavidKiryazi

            Hi, I tried your code on my machine .Net 2.0 vs2005 and it seems to work fine. I added a line that refreshes the form so maybe try this and see if the results are any different.

            private void button1_Click(object sender, EventArgs e)
            {
            for (int j = 0; j < 5; j++)
            {
            zoomOutPicture((j + 1) * 10);
            this.Refresh(); // <---- line added that references the form with the picture box on it
            System.Threading.Thread.Sleep(1000);
            }
            }

            Dave

            J Offline
            J Offline
            jisan22
            wrote on last edited by
            #5

            Hi Dave, Thanks a lot, that did the trick.

            1 Reply Last reply
            0
            • L Luc Pattyn

              you could "solve" it with some Invalidate() or Refresh() calls, but your approach is fundamentally flawed, since you are blocking the GUI thread for the entire duration of this action, making moving, resizing, e.a. impossible. The correct approach is by using either a separate thread or a timer; since the actions involve Controls, which need to be handled on the main thread anyway, your best option is to start a Windows.Forms.Timer :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


              J Offline
              J Offline
              jisan22
              wrote on last edited by
              #6

              Hi Luc, I tried the Invalidate() with out luck but the Refresh() is working. I will look into the timer when I get a bit more time bur for now Refresh() does the trick. Thank you.

              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