Редагувати

Поділитися через


ControlPaint.FillReversibleRectangle(Rectangle, Color) Method

Definition

Draws a filled, reversible rectangle on the screen.

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)

Parameters

rectangle
Rectangle

The Rectangle that represents the dimensions of the rectangle to fill, in screen coordinates.

backColor
Color

The Color of the background behind the fill.

Examples

The following code example demonstrates using the FillReversibleRectangle method. To run the example, paste the following code in a form. Add a button named Button2 to the form and ensure all events are connected to their event handlers.

//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

Remarks

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

The results of this method can be reversed by drawing the same rectangle again. Drawing a rectangle 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

See also