.NET Framework Class Library
ControlPaint..::.FillReversibleRectangle Method

Draws a filled, reversible rectangle on the screen.

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

Visual Basic (Declaration)
<UIPermissionAttribute(SecurityAction.LinkDemand, Window := UIPermissionWindow.AllWindows)> _
Public Shared Sub FillReversibleRectangle ( _
    rectangle As Rectangle, _
    backColor As Color _
)
Visual Basic (Usage)
Dim rectangle As Rectangle
Dim backColor As Color

ControlPaint.FillReversibleRectangle(rectangle, _
    backColor)
C#
[UIPermissionAttribute(SecurityAction.LinkDemand, Window = UIPermissionWindow.AllWindows)]
public static void FillReversibleRectangle(
    Rectangle rectangle,
    Color backColor
)
Visual C++
[UIPermissionAttribute(SecurityAction::LinkDemand, Window = UIPermissionWindow::AllWindows)]
public:
static void FillReversibleRectangle(
    Rectangle rectangle, 
    Color backColor
)
JScript
public static function FillReversibleRectangle(
    rectangle : Rectangle, 
    backColor : Color
)

Parameters

rectangle
Type: System.Drawing..::.Rectangle
The Rectangle that represents the dimensions of the rectangle to fill, in screen coordinates.
backColor
Type: System.Drawing..::.Color
The Color of the background behind the fill.
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.

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.

Visual Basic
' 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
C#
    //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);
    }
Visual C++
//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 );
}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Tags :


Page view tracker