ControlPaint.FillReversibleRectangle(Rectangle, Color) 方法

定义

在屏幕上绘制实心的可逆矩形。

public:
 static void FillReversibleRectangle(System::Drawing::Rectangle rectangle, System::Drawing::Color backColor);
public static void FillReversibleRectangle (System.Drawing.Rectangle rectangle, System.Drawing.Color backColor);
static member FillReversibleRectangle : System.Drawing.Rectangle * System.Drawing.Color -> unit
Public Shared Sub FillReversibleRectangle (rectangle As Rectangle, backColor As Color)

参数

rectangle
Rectangle

代表要填充矩形的尺寸的 Rectangle(采用屏幕坐标)。

backColor
Color

填充区域的背景的 Color

示例

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

//When the mouse hovers over Button2, its ClientRectangle is filled.
void Button2_MouseHover( Object^ sender, System::EventArgs^ /*e*/ )
{
   Control^ senderControl = dynamic_cast<Control^>(sender);
   Rectangle screenRectangle = senderControl->RectangleToScreen( senderControl->ClientRectangle );
   ControlPaint::FillReversibleRectangle( screenRectangle, senderControl->BackColor );
}

// When the mouse leaves Button2, its ClientRectangle is cleared by
// calling the FillReversibleRectangle method again.
void Button2_MouseLeave( Object^ sender, System::EventArgs^ /*e*/ )
{
   Control^ senderControl = dynamic_cast<Control^>(sender);
   Rectangle screenRectangle = senderControl->RectangleToScreen( senderControl->ClientRectangle );
   ControlPaint::FillReversibleRectangle( screenRectangle, senderControl->BackColor );
}
//When the mouse hovers over Button2, its ClientRectangle is filled.
private void Button2_MouseHover(object sender, System.EventArgs e)
{
    Control senderControl = (Control) sender;
    Rectangle screenRectangle = senderControl.RectangleToScreen(
        senderControl.ClientRectangle);
    ControlPaint.FillReversibleRectangle(screenRectangle, 
        senderControl.BackColor);
}

// When the mouse leaves Button2, its ClientRectangle is cleared by
// calling the FillReversibleRectangle method again.
private void Button2_MouseLeave(object sender, System.EventArgs e)
{
    Control senderControl = (Control) sender;
    Rectangle screenRectangle = senderControl.RectangleToScreen(
        senderControl.ClientRectangle);
    ControlPaint.FillReversibleRectangle(screenRectangle, 
        senderControl.BackColor);
}
' When the mouse hovers over Button2, its ClientRectangle is filled.
Private Sub Button2_MouseHover(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button2.MouseHover

    Dim senderControl As Control = CType(sender, Control)
    Dim screenRectangle As Rectangle = _
        senderControl.RectangleToScreen(senderControl.ClientRectangle)
    ControlPaint.FillReversibleRectangle(screenRectangle, _
        senderControl.BackColor)
End Sub


' When the mouse leaves Button2, its ClientRectangle is cleared by
' calling the FillReversibleRectangle method again.
Private Sub Button2_MouseLeave(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button2.MouseLeave

    Dim senderControl As Control = CType(sender, Control)
    Dim screenRectangle As Rectangle = _
        senderControl.RectangleToScreen(senderControl.ClientRectangle)
    ControlPaint.FillReversibleRectangle(screenRectangle, _
        senderControl.BackColor)
End Sub

注解

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

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

适用于

另请参阅