Hi everyone. I have a situation where I have a method that is a draw line tool. You press the mouse down, drag and it draws a line. The Mouse UP captures the AnchorX/Y position and the drag captures the EndX/EndY positions. That works very nicely until I try to move it over into an offline buffered picture.
My issue is when I instantiate a new picture with DrawLineToolBuffer = new picture(Width,Height) the width/height of my drawing is the W/H of my canvas. I know that is because I am telling it to do that with (width/height). I am struggling to find the right variable to use as the W/H to dynamically give me the proper height and width of the actual drawn line. I have tried combinations of add/subtracting the EndX/Y and AnchorX/Y with no success. Any ideas on this one?
The DrawLineToolBuffer picture is declared as a property
This method is called out of my Canvas’ paint event:
Sub mDrawLineMethod(g as graphics)
DrawLineToolBuffer = new picture(Width,Height)
DrawLineToolBuffer.Graphics.ForeColor =CampusMapWindow.kBlack
DrawLineToolBuffer.Graphics.PenHeight = 1
DrawLineToolBuffer.Graphics.PenWidth = 5
DrawLineToolBuffer.Graphics.DrawLine(LineToolAnchorX-4,LineToolAnchorY+10,LineToolEndX-4,LineToolEndY+10)
g.DrawPicture(DrawLineToolBuffer,0,0)
Dave thanks for the reply. Essentially yes I am doing those steps and my lines are drawing nicely except the height and width of picturebuffer are huge since I used “New picture(width , height)” above instead of the actual h/w of the drawn line. I am stuck there if that makes since?
width should be the absolute value of the difference in X, and height the same for Y.
Then you need to offset the lines coordinates so it draws within those bounds. I think just use the min X and Y from either endpoint. Then draw the picture using that same offset.