
However to avoid flicker it is highly recommended to use a DoubleBuffered control, maybe a Panel subclass like this: class DrawPanel : Panel Panel3.AutoScrollMinSize = new Size(500, 500) // use the size you want to allow! The only settings needed for the Panel are panel3.AutoScroll = true
The only line in the TrackBar's Scroll event is to trigger the Paint event: panel3.Invalidate(). I first translate and then scale so I don't have to calculate scaled poitions. Anything draw will always be draw with 1 pxiel width, though. I draw with a tiny pen width so the width of the drawing only changes once the resulting pen goes over 1 pixel. My coordinates go from the negative to the positive so you can see that this works nicely. I draw an orange circle in the center to show this point is invariant. Using(Pen pen = new Pen(Color.Yellow, 0.1f)) move the scrolled center to the origon you determine the value of the zooming! G.DrawEllipse(Pens.Orange, center.X - 3, center.Y - 3, 6, 6) Point center = new Point(sz.Width / 2, sz.Height / 2) This is the code in the Paint event: Size sz = panel3.ClientSize If you then add the current scrolling position to the translation you are also done. Or you can turn on AutoScroll for the canvas control and also set a large enough AutoScrollMinSize. You can keep AutoScroll = false and nest the canvas control inside another control, usually a Panel, which has AutoScroll = true next make the canvas control big enough to always hold your drawing and you're done. Once you have achieved all this you almost certainly will want to allow scrolling. Once you do you can move the origin of the graphics viewport to this point with TranslateTransform. When zooming (just like rotating) you always need to know the center point of the zoom (or the rotation.) By default this is the origin (0,0). This is a non-obvious concept: Just what is the center of your drawing surface? You also asked about keeping the drawing 'centered'. You can scale the Graphics object to create zoomed graphics with ScaleTransform.Īs I mentioned, this will include the widths of pens, font sizes and also any images you draw (though not the hatches of a HatchBrush). This is not so hard, provided you know all the puzzle pieces. Private void buttoncleardraw_Click(object sender, EventArgs e)
MessageBox.Show("No data to draw, perform analysis first.")
Private void pictureBoxDraw_Paint(object sender, PaintEventArgs e)Ĭenterpointx = /2 Ĭenterpointy = /2 I need to zoom on that drawing.Is it possible to code something like autocad feature "zoom/extent"? Pen myPen = new Pen(Color.Black) My code is working this image shows what happens when I click on Draw button. I've seen few questions about this problem, I tried every solution but none of them worked for my case.