last day (15 days later) » 

11:20
-2
Q: Why am I getting wrong rectangle(translated), while translation of rectangle(GraphicsPath) on the PictureBox in c#

thippu 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 accord...

TaW
TaW
What SizeMode does the pbox have? Any other mode than Normal will require a coordinate transformation. Some examples
@TaW thanks for the reply, it is "normal"
@TaW , size 640*480
What is wrong? why devoted?
TaW
TaW
Nothing much wrong. Many folks downvote without much reason and will not explain. A few issues though: The links are not embedded and and images are way too large and should be real screenshots, not photographs. Also we would like to see the wrong result and the expected one. Also we'd like to see where the code you show resided. (It also has numerous issues wrt to efficiency, resource leaks etc, but that is no reason to downvote a question..)
Actually, it was from a remote development server, there is no way of connecting it to the internet and the right now my issues are how to translate shape(GraphicPath and because shape could be rectangle or circle or polyline) on the picture box along with the cursor move point and after this I will work on resizing (scaling) the shape also
TaW
TaW
Note that as the rectangle doesn't sit at the origin its transform will not sit at the mouse locaton.
Simplified test: GraphicsPath path = new GraphicsPath(); private void PictureBox1_MouseClick(object sender, MouseEventArgs e) { Rectangle rect = new Rectangle(0, 0, 200, 200); path.Reset(); path.AddRectangle(rect); Matrix MatTranslate = new Matrix(); MatTranslate.Translate(e.X, e.Y); path.Transform(MatTranslate); pictureBox1.Invalidate(); } private void PictureBox1_Paint(object sender, PaintEventArgs e) { using (Pen mpen = new Pen(Color.Red, 2)) e.Graphics.DrawPath(mpen, path); }
11:20
@TaW Thanks for the solution, I will try that definitely.
@TaW I tried the solution you gave works for me, I can mark this as the solution if you put on as an answer and It would be better if possible cursor can come in the center of the rectangle after the move like offsetting, I'll try, thank you.
TaW
TaW
Hi
Hi, @TaW tried the solution with a new project, it worked perfectly, but when I did same thing on the actual project, rectangle not translated properly
Image on the picture box is zoomed
maybe because of this it is not working I think.
TaW
TaW
For zoomed (or stretched or centered) images you need to transform the mouse coordinates to image coordinates and maybe back. See the examples in the links in my 1st comment for scale and unscale functions!
okay, I will come later here.
12:25
Hi, @TaW
TaW
TaW
Hi
I'm sorry to say this, I checked SizeMode of the picture box it says normal, I was wrong about zoomed image
Can I share the video whats happening ?
on pictureBox
TaW
TaW
Maybe.Try!
Did you see? @Taw
Gave access, access it now
TaW
TaW
12:43
thanks
OK; this is what I meant when I wrote: Note that as the rectangle doesn't sit at the origin its transform will not sit at the mouse location. You will have to add/subtract the offset(location) of the rectangle from the mouse position...: MatTranslate.Translate(e.X - rect.X, e.Y - rect.Y);
Perfect, @TaW Thank you so much. understood
TaW
TaW
Good luck then :-)
Thanks

last day (15 days later) »