Export (0) Print
Expand All

ControlPaint.FillReversibleRectangle Method

Draws a filled, reversible rectangle on the screen.

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

[UIPermissionAttribute(SecurityAction.LinkDemand, Window = UIPermissionWindow.AllWindows)]
public static void FillReversibleRectangle(
	Rectangle rectangle,
	Color backColor
)

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.

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.

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. 
	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);
	}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft