sagey Posted February 5, 2004 Posted February 5, 2004 i'm trying to draw crosshairs that follow the mouse around the screen. The following code works. but not quite, it draws a new crosshair for every mouse move, but doesn't remove the old one, so i end up with a screen full of vertical and horizontal lines. how do i remove the last lines drawn on every mouse move? public void MyMouseMove( Object sender, MouseEventArgs e ) { Pen blackPen = new Pen(Color.FromArgb(128,0,0,255), 1); Graphics g = SelectionRectangle.ActiveForm.CreateGraphics(); // Create coordinates of points that define line. float formLeft = this.Left; float formTop = this.Top ; float formRight = this.Right ; float formBottom = this.Bottom ; mouseX = e.X ; mouseY = e.Y ; // Draw line to screen. g.DrawLine(blackPen,0,mouseY,mouseX,mouseY ); g.DrawLine(blackPen, mouseX, 0, mouseX,mouseY); g.DrawLine(blackPen, formRight, mouseY, mouseX, mouseY); g.DrawLine(blackPen, mouseX, formBottom,mouseX, mouseY); Quote
slantz Posted February 11, 2004 Posted February 11, 2004 I would probably approach it differently. I would have the crosshair on its own surface/graphcis object, and then blit that over to the desired X/Y location each frame. No matter how you do it, you'll probably have to rebuild your primary surface from its component layers each frame, otherwise you'll have residue from previous frames sitting around. -Hiro_Antagonist Quote
mdpotter Posted February 12, 2004 Posted February 12, 2004 Take a look at ControlPaint.DrawReversibleLine(). It is in screen coordinates but the transformation is pretty simplistic. It will do what you want. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.