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. Windows Forms
  4. How to stop updating a PictureBox? [modified]

How to stop updating a PictureBox? [modified]

Scheduled Pinned Locked Moved Windows Forms
tutorialquestionannouncement
5 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.
  • M Offline
    M Offline
    MichaelCoder
    wrote on last edited by
    #1

    Hi..., I want to write a zoom function for a PictureBox. Therefore I have to change some values (Left, Top, Width, and Height) of the PictureBox. The PictureBox is redrawn, when I just change one of theses values. So, when I change all 4 values the PictureBox gets flickering and jumping around. How to stop/activate the Redrawing of a PictureBox. This is my code:

    private void CalcPictureBox1()
    {
      // NEED: deactivate pictureBox, that no changes update PictureBox
      
      int zoomedWidth = (int)(bitmapDepthBuffer.Width \* pBoxZoomFactor);
      int zoomedHeight = (int)(bitmapDepthBuffer.Height \* pBoxZoomFactor);
      if (zoomedWidth > panelDepthBuffer.Width)
      {
        this.pBoxDepthBuffer.Left = 0;
      }
      else
      {
        this.pBoxDepthBuffer.Left = (panelDepthBuffer.Width - zoomedWidth) / 2;
      }
      if (zoomedHeight > panelDepthBuffer.Height)
      {
        this.pBoxDepthBuffer.Top = 0;
      }
      else
      {
        this.pBoxDepthBuffer.Top = (panelDepthBuffer.Height - zoomedHeight) / 2;
      }
      this.pBoxDepthBuffer.Width = zoomedWidth;
      this.pBoxDepthBuffer.Height = zoomedHeight;
    
      // NEED: activate pictureBox, that changes update PictureBox
    
    }
    

    Thank you in advance, Michael

    modified on Friday, June 20, 2008 4:33 PM

    M C 2 Replies Last reply
    0
    • M MichaelCoder

      Hi..., I want to write a zoom function for a PictureBox. Therefore I have to change some values (Left, Top, Width, and Height) of the PictureBox. The PictureBox is redrawn, when I just change one of theses values. So, when I change all 4 values the PictureBox gets flickering and jumping around. How to stop/activate the Redrawing of a PictureBox. This is my code:

      private void CalcPictureBox1()
      {
        // NEED: deactivate pictureBox, that no changes update PictureBox
        
        int zoomedWidth = (int)(bitmapDepthBuffer.Width \* pBoxZoomFactor);
        int zoomedHeight = (int)(bitmapDepthBuffer.Height \* pBoxZoomFactor);
        if (zoomedWidth > panelDepthBuffer.Width)
        {
          this.pBoxDepthBuffer.Left = 0;
        }
        else
        {
          this.pBoxDepthBuffer.Left = (panelDepthBuffer.Width - zoomedWidth) / 2;
        }
        if (zoomedHeight > panelDepthBuffer.Height)
        {
          this.pBoxDepthBuffer.Top = 0;
        }
        else
        {
          this.pBoxDepthBuffer.Top = (panelDepthBuffer.Height - zoomedHeight) / 2;
        }
        this.pBoxDepthBuffer.Width = zoomedWidth;
        this.pBoxDepthBuffer.Height = zoomedHeight;
      
        // NEED: activate pictureBox, that changes update PictureBox
      
      }
      

      Thank you in advance, Michael

      modified on Friday, June 20, 2008 4:33 PM

      M Offline
      M Offline
      Matthew Butler 0
      wrote on last edited by
      #2

      To update position and size at the same time, you can use...

      .SetBounds(left, top, width, height);

      [also: .Scale may be of use] Hope this helps.

      Matthew Butler

      M 1 Reply Last reply
      0
      • M Matthew Butler 0

        To update position and size at the same time, you can use...

        .SetBounds(left, top, width, height);

        [also: .Scale may be of use] Hope this helps.

        Matthew Butler

        M Offline
        M Offline
        MichaelCoder
        wrote on last edited by
        #3

        Hi Matthew, thank you for the tip, but it didn't help, whyever. The PictureBox on the panel is still jumping around, when I change it with:

        this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);

        ...

        pBoxDepthBuffer.SizeMode = PictureBoxSizeMode.Zoom;
        panelDepthBuffer.Controls.Add(pBoxDepthBuffer);
        panelDepthBuffer.AutoScroll = true;

        ...

        this.pBoxDepthBuffer.SetBounds(newLeft, newTop, zoomedWidth, zoomedHeight);

        I've also changed the Style of the Form with this.SetStyle to DoubleBuffering. Nothing helped. Do you have any further ideas? Thanks, Michael

        M 1 Reply Last reply
        0
        • M MichaelCoder

          Hi Matthew, thank you for the tip, but it didn't help, whyever. The PictureBox on the panel is still jumping around, when I change it with:

          this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);

          ...

          pBoxDepthBuffer.SizeMode = PictureBoxSizeMode.Zoom;
          panelDepthBuffer.Controls.Add(pBoxDepthBuffer);
          panelDepthBuffer.AutoScroll = true;

          ...

          this.pBoxDepthBuffer.SetBounds(newLeft, newTop, zoomedWidth, zoomedHeight);

          I've also changed the Style of the Form with this.SetStyle to DoubleBuffering. Nothing helped. Do you have any further ideas? Thanks, Michael

          M Offline
          M Offline
          MichaelCoder
          wrote on last edited by
          #4

          Hi..., I have tried this rude method by setting the image first to null, changing the Bounds and initialalizing the image again:

            this.pBoxDepthBuffer.Image = null;
            this.pBoxDepthBuffer.SetBounds(newLeft, newTop, zoomedWidth, zoomedHeight);
            this.pBoxDepthBuffer.Image = bitmapDepthBuffer;
          

          This works now for me. Thank you, Michael

          1 Reply Last reply
          0
          • M MichaelCoder

            Hi..., I want to write a zoom function for a PictureBox. Therefore I have to change some values (Left, Top, Width, and Height) of the PictureBox. The PictureBox is redrawn, when I just change one of theses values. So, when I change all 4 values the PictureBox gets flickering and jumping around. How to stop/activate the Redrawing of a PictureBox. This is my code:

            private void CalcPictureBox1()
            {
              // NEED: deactivate pictureBox, that no changes update PictureBox
              
              int zoomedWidth = (int)(bitmapDepthBuffer.Width \* pBoxZoomFactor);
              int zoomedHeight = (int)(bitmapDepthBuffer.Height \* pBoxZoomFactor);
              if (zoomedWidth > panelDepthBuffer.Width)
              {
                this.pBoxDepthBuffer.Left = 0;
              }
              else
              {
                this.pBoxDepthBuffer.Left = (panelDepthBuffer.Width - zoomedWidth) / 2;
              }
              if (zoomedHeight > panelDepthBuffer.Height)
              {
                this.pBoxDepthBuffer.Top = 0;
              }
              else
              {
                this.pBoxDepthBuffer.Top = (panelDepthBuffer.Height - zoomedHeight) / 2;
              }
              this.pBoxDepthBuffer.Width = zoomedWidth;
              this.pBoxDepthBuffer.Height = zoomedHeight;
            
              // NEED: activate pictureBox, that changes update PictureBox
            
            }
            

            Thank you in advance, Michael

            modified on Friday, June 20, 2008 4:33 PM

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

            I would never bother with a picture box, I'd just draw the bitmap myself.

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            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