drawing cross hair +C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div class=KonaBody>     im 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 doesnt remove the old one, so i end up with a screen full of vertical and horizontal lines.<br/><br/>how do i remove the last lines drawn on every mouse move?<br/><br/>public void MyMouseMove( Object sender, MouseEventArgs e )<br/> { <br/> <br/> Pen blackPen = new Pen(Color.FromArgb(128,0,0,255), 1); // Pen blackPen = new Pen(Color.FromArgb(0,0,0,255), 1);<br/>   Graphics g = SelectionRectangle.ActiveForm.CreateGraphics();<br/> // Create coordinates of points that define line.<br/> float formLeft = this.Left;<br/> float formTop = this.Top ;<br/> float formRight = this.Right ;<br/> float formBottom = this.Bottom ;<br/> mouseX = e.X ;<br/> mouseY = e.Y ;<br/> // Draw line to screen.<br/> g.DrawLine(blackPen,0,mouseY,mouseX,mouseY );<br/> g.DrawLine(blackPen, mouseX, 0, mouseX,mouseY);<br/> g.DrawLine(blackPen, formRight, mouseY, mouseX, mouseY);<br/> g.DrawLine(blackPen, mouseX, formBottom,mouseX, mouseY);<br/> <hr class="sig algates

View the full article
 
Back
Top