Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# picturebox
The image on picturebox go back to the original size and buffer gone broken infront
of the picturebox....
help me please...
this is the code...
public partial class ImageDetail : UserControl
    {
        public delegate void onClose();
        public event onClose close;
        Image pbImage;
        public ImageDetail(Image img)
        {            
            InitializeComponent();
            pictureBox.Image = img;
            pbImage = img;
            pictureBox.Width = this.pbImage.Width;
            pictureBox.Height = this.pbImage.Height;
            panel2.AutoScroll = true;
            panel2.HorizontalScroll.Maximum = img.Width;
            panel2.VerticalScroll.Maximum   = img.Height;
            panel2.HorizontalScroll.Minimum = 0;
            panel2.VerticalScroll.Minimum   = 0;
            panel2.SetAutoScrollMargin(10, 10);            
        }
        
        private void label2_Click(object sender, EventArgs e)
        {
            if (close != null)
                close(); 
        }        
        
        private void DrawImage(int startX, int startY)
        {            
            if (this.pbImage == null) { return; }
            
            Graphics pbGraphics = this.pictureBox.CreateGraphics();
            BufferedGraphicsContext currentGraphicsContext = BufferedGraphicsManager.Current;
            Rectangle targetRect = new Rectangle(startX, startY, (this.pbImage.Width + tmpWidth), (this.pbImage.Height + tmpHeight));
            using (BufferedGraphics pbGDIBuffer = currentGraphicsContext.Allocate(pbGraphics, targetRect))
            {
                Rectangle drawRect = new Rectangle(startX, startY, (this.pbImage.Width + tmpWidth), (this.pbImage.Height + tmpHeight));
                
                pbGDIBuffer.Graphics.DrawImageUnscaledAndClipped(this.pbImage, drawRect);
                pbGDIBuffer.Render();                
            }
            pictureBox.Width = this.pbImage.Width + tmpWidth;
            pictureBox.Height = this.pbImage.Height + tmpHeight;
        }             
 
        int tmpWidth = 0, tmpHeight = 0;
        private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e)
        {
            tmpWidth = tmpWidth + ((this.pbImage.Width * 20) / 100);
            tmpHeight = tmpHeight + ((this.pbImage.Height * 20) / 100);
            
           pictureBox.Width = this.pbImage.Width + tmpWidth;
            pictureBox.Height = this.pbImage.Height + tmpHeight;
            pictureBox.Refresh();
            DrawImage(0, 0);
        }
 
        private void toolStripSplitButton2_ButtonClick(object sender, EventArgs e)
        {
            if(tmpWidth > 0)
                tmpWidth = tmpWidth - ((this.pbImage.Width * 20) / 100);
            if(tmpHeight > 0)
                tmpHeight = tmpHeight - ((this.pbImage.Height * 20) / 100);
            if (tmpHeight < 0)
                tmpHeight = 0;
            if (tmpWidth < 0)
                tmpWidth = 0;
            pictureBox.Refresh();
            DrawImage(0, 0);                      
        }
 
        private void panel2_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox.Width = this.pbImage.Width + tmpWidth;
            pictureBox.Height = this.pbImage.Height + tmpHeight;
        }
 
        private void panel2_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox.Width = this.pbImage.Width + tmpWidth;
            pictureBox.Height = this.pbImage.Height + tmpHeight;
        }
        
    }
Posted 1-Oct-12 17:41pm
Edited 1-Oct-12 17:46pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Im going to assume this is WinForms, it sure looks like that, but im not certain. Here is code for what you are trying to achieve:
http://www.bobpowell.net/zoompicbox.htm[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 389
1 Sergey Alexandrovich Kryukov 362
2 CPallini 130
3 Abdul Samad KP 125
4 Richard MacCutchan 110
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,680
2 CPallini 4,850
3 George Jonsson 3,454
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100