Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
DrawReversibleLine Method

ControlPaint.DrawReversibleLine Method

Draws a reversible line on the screen within the specified starting and ending points and with the specified background color.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[UIPermissionAttribute(SecurityAction.LinkDemand, Window = UIPermissionWindow.AllWindows)]
public static void DrawReversibleLine(
	Point start,
	Point end,
	Color backColor
)

Parameters

start
Type: System.Drawing.Point

The starting Point of the line, in screen coordinates.

end
Type: System.Drawing.Point

The ending Point of the line, in screen coordinates.

backColor
Type: System.Drawing.Color

The Color of the background behind the line.

The backColor parameter is used to calculate the fill color of the line so that it is always visible against the background.

The results of this method can be reversed by drawing the same line again. Drawing a line using this method is similar to inverting a region of the screen, except that it provides better performance for a wider variety of colors.

The following code example demonstrates using the ControlPaint.DrawReversibleLine and Control.PointToScreen methods. To run the example, paste the following code in a form. Add a button named Button3 to the form and ensure all events are connected to their event handlers.

	// When the mouse hovers over Button3, two reversible lines are  
	// drawn using the corner coordinates of Button3, which are first  
	// converted to screen coordinates. 
	private void Button3_MouseHover(object sender, System.EventArgs e)
	{
		ControlPaint.DrawReversibleLine(Button3.PointToScreen(
			new Point(0, 0)), Button3.PointToScreen(
			new Point(Button3.ClientRectangle.Right, 
			Button3.ClientRectangle.Bottom)), SystemColors.Control);
		
		ControlPaint.DrawReversibleLine(Button3.PointToScreen(
			new Point(Button3.ClientRectangle.Right, 
			Button3.ClientRectangle.Top)), 
			Button3.PointToScreen(new Point(Button1.ClientRectangle.Left, 
			Button3.ClientRectangle.Bottom)), SystemColors.Control);
	}

	// When the mouse moves from Button3, the reversible lines are erased by 
	// using the same coordinates as are used in the Button3_MouseHover method. 
	private void Button3_MouseLeave(object sender, System.EventArgs e)
	{
		ControlPaint.DrawReversibleLine(Button3.PointToScreen(
			new Point(0, 0)), Button3.PointToScreen(
			new Point(Button3.ClientRectangle.Right, 
			Button3.ClientRectangle.Bottom)), SystemColors.Control);
		
		ControlPaint.DrawReversibleLine(Button3.PointToScreen(
			new Point(Button3.ClientRectangle.Right, 
			Button3.ClientRectangle.Top)), 
			Button3.PointToScreen(new Point(Button3.ClientRectangle.Left,
			Button3.ClientRectangle.Bottom)), SystemColors.Control);
	}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft