Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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);

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...