thippu
Active member
- I had drawn a rectangle shape(GraphicsPath) on the PictureBox in c#.link
- I will pick the mouse point(x,y) if a user clicks on the rectangle shape and moves the mouse cursor on the picture box, I will collect the mouse move point also.mouse move point was
- I want to do rectangle translation according to mouse move on the picture box.
- After the translation, I'm trying to draw the translated rectangle but coordinates of the rectangle are wrong(They are not drawn on the position of the cursor).wrong coordinates and After the translation image and rectangle points before translation link
- Could not able to figure it out.help me. if u have a material let me know how to.
- tried to do this link1, link2, link3 did same result.
C#:
Rectangle temp=new Rectangle();
GraphicsPath path=new GraphicsPath();
Graphics g=Graphics.FromImage(m_ParentImage);
//defined orginal rectangle for translation
Rectangle rect =new Rectangle();
rect.X=zone.ZonePoints[0].X;
rect.Y=480-zone.ZonePoints[0].Y;
rect.Width=Math.Abs(zone.ZonePoints[2].X-rect.X);
rect.Height=Math.Abs((480-zone.ZonePoints[2].Y)-rect.Y);
path.AddRectangle(rect);
temp=rect;
//getting mouse move point.
Point xyPoint=new Point();
xyPoint.X=m_right_button_move_x;
xyPoint.Y=m_right_button_move_y;
//defining translation matrix
Matrix MatTranslate=new Matrix();
MatTranslate.Translate(xyPoint.X,xyPoint.Y);
path.Tranform(MatTranslate);
//getting new rectanglef with translated points
RectangleF temprect=path.GetBounds();
Pen mpen=new Pen(Color.Red,2);
g.DrawPath(mpen,path);//drawing the new rectangle on the picture box with color red.