Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I trying to implement a Zoomable and panable image But in <winforms>without the scrollbars value proprety,
with the zooming everything fine,
the problem is
but when I try to calculate the x and y for panning everything goes wrong ,image goes off borders and acts strangely ,


heres my code with the scroll bar values and here it working fine :
mousemove event
C#
if (m_drawing && CurrentZoomRate >1)
 {
          int DeltaX = (m_StartingPoint.X - e.X);
          int DeltaY = (m_StartingPoint.Y - e.Y);
          this.pbImage.x = DeltaX;
          this.pbImage.y = DeltaY;
          pbimage.AutoScrollPosition= new System.Drawing.Point(Math.Abs(DeltaX - AutoScrollPosition.X), Math.Abs(DeltaY - AutoScrollPosition.Y));


and here when i trying to do it without out the scroll bars(that my goal without them)
and everything goes wrong
int DeltaX = (m_StartingPoint.X - e.X);
int DeltaY = (m_StartingPoint.Y - e.Y);
this.pbImage.x = DeltaX;
this.pbImage.y = DeltaY;
this.pbImage.Refresh();


and here is my paintevent (taken from bobpowell.net)
C#
Matrix mx = new Matrix(_zoom, 0, 0, _zoom, 0, 0);
       //now translate the matrix into position for the scrollbars
       mx.Translate(this.x / _zoom, this.y / _zoom);
       //use the transform
       e.Graphics.Transform = mx;
       //and the desired interpolation mode
       e.Graphics.InterpolationMode = _interpolationMode;
       //Draw the image ignoring the images resolution settings.
       e.Graphics.DrawImage(_image, new Rectangle(0, 0, this._image.Width, this._image.Height), 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel);
       base.OnPaint(e);


can anyone have idea how to preform this calculations ?

I also trying to make the invisible but the ccalculation of this
"
VB
this.AutoScrollMinSize=new Size(
         (int)(this._image.Width*_zoom+0.5f),
         (int)(this._image.Height*_zoom+0.5f)


always turn the invisible to true , trying to set it of in the paint event jst get my endless flickering .
Posted

1 solution

Well...perhaps if you included the PictureBox original x and y coordinates in teh calculation it might help?

Start with the debugger: put a breakpoint on the line:
C#
int DeltaX = (m_StartingPoint.X - e.X);
and step through your code - look at the values and work out what they should be, and compare that to what they are.
Then you can work out what exactly you are doing wrong - we can't give you exact instructions because we can't run your code and see exactly how you are doing everything!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900