ControlPaint.DrawReversibleLine(Point, Point, Color) 方法

定义

在屏幕上指定的起始点和结束点内绘制具有指定背景色的可逆线。

public:
 static void DrawReversibleLine(System::Drawing::Point start, System::Drawing::Point end, System::Drawing::Color backColor);
public static void DrawReversibleLine (System.Drawing.Point start, System.Drawing.Point end, System.Drawing.Color backColor);
static member DrawReversibleLine : System.Drawing.Point * System.Drawing.Point * System.Drawing.Color -> unit
Public Shared Sub DrawReversibleLine (start As Point, end As Point, backColor As Color)

参数

start
Point

用屏幕坐标表示的线的起始 Point

end
Point

用屏幕坐标表示的线的结束 Point

backColor
Color

线的背景的 Color

示例

下面的代码示例演示了如何使用 ControlPaint.DrawReversibleLineControl.PointToScreen 方法。 若要运行示例,请将以下代码粘贴到窗体中。 添加一个名为 Button3 窗体的按钮,并确保所有事件都连接到其事件处理程序。

// When the mouse hovers over Button3, two reversible lines are 
// drawn using the corner coordinates of Button3, which are first 
// converted to screen coordinates.
void Button3_MouseHover( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   ControlPaint::DrawReversibleLine( Button3->PointToScreen( Point(0,0) ), Button3->PointToScreen( Point(Button3->ClientRectangle.Right,Button3->ClientRectangle.Bottom) ), SystemColors::Control );
   ControlPaint::DrawReversibleLine( Button3->PointToScreen( Point(Button3->ClientRectangle.Right,Button3->ClientRectangle.Top) ), Button3->PointToScreen( 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.
void Button3_MouseLeave( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   ControlPaint::DrawReversibleLine( Button3->PointToScreen( Point(0,0) ), Button3->PointToScreen( Point(Button3->ClientRectangle.Right,Button3->ClientRectangle.Bottom) ), SystemColors::Control );
   ControlPaint::DrawReversibleLine( Button3->PointToScreen( Point(Button3->ClientRectangle.Right,Button3->ClientRectangle.Top) ), Button3->PointToScreen( Point(Button3->ClientRectangle.Left,Button3->ClientRectangle.Bottom) ), SystemColors::Control );
}
// 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);
}
' 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 Sub Button3_MouseHover(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button3.MouseHover

    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)
End Sub

' 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 Sub Button3_MouseLeave(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button3.MouseLeave

    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)
End Sub

注解

backColor 参数用于计算线条的填充颜色,以便始终对背景可见。

此方法的结果可以通过再次绘制同一行来反转。 使用此方法绘制线条类似于反转屏幕区域,只是它为更广泛的颜色提供更好的性能。

适用于

另请参阅