ControlPaint.DrawReversibleLine(Point, Point, Color) Method

Definition

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

C#
public static void DrawReversibleLine(System.Drawing.Point start, System.Drawing.Point end, System.Drawing.Color backColor);

Parameters

start
Point

The starting Point of the line, in screen coordinates.

end
Point

The ending Point of the line, in screen coordinates.

backColor
Color

The Color of the background behind the line.

Examples

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.

C#
// 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);
}

Remarks

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.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also