ControlPaint.DrawFocusRectangle Method

Definition

Draws a focus rectangle.

Overloads

DrawFocusRectangle(Graphics, Rectangle, Color, Color)

Draws a focus rectangle on the specified graphics surface and within the specified bounds.

DrawFocusRectangle(Graphics, Rectangle)

Draws a focus rectangle on the specified graphics surface and within the specified bounds.

DrawFocusRectangle(Graphics, Rectangle, Color, Color)

Source:
ControlPaint.cs
Source:
ControlPaint.cs
Source:
ControlPaint.cs

Draws a focus rectangle on the specified graphics surface and within the specified bounds.

C#
public static void DrawFocusRectangle(System.Drawing.Graphics graphics, System.Drawing.Rectangle rectangle, System.Drawing.Color foreColor, System.Drawing.Color backColor);

Parameters

graphics
Graphics

The Graphics to draw on.

rectangle
Rectangle

The Rectangle that represents the dimensions of the grab handle glyph.

foreColor
Color

The Color that is the foreground color of the object to draw the focus rectangle on.

backColor
Color

The Color that is the background color of the object to draw the focus rectangle on.

Examples

The following code example demonstrates using the DrawFocusRectangle method and the Control.Handle property. To run this example, paste the following code in a form. Add two buttons named Button1 and Button2 to the form and ensure all events are connected to their event handlers.

C#
// This method draws a focus rectangle on Button2 using the 
// handle and client rectangle of Button2.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    ControlPaint.DrawFocusRectangle(Graphics.FromHwnd(Button2.Handle), 
        Button2.ClientRectangle);
}

Remarks

A focus rectangle is a dotted rectangle that Windows uses to indicate what control has the current keyboard focus.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

DrawFocusRectangle(Graphics, Rectangle)

Source:
ControlPaint.cs
Source:
ControlPaint.cs
Source:
ControlPaint.cs

Draws a focus rectangle on the specified graphics surface and within the specified bounds.

C#
public static void DrawFocusRectangle(System.Drawing.Graphics graphics, System.Drawing.Rectangle rectangle);

Parameters

graphics
Graphics

The Graphics to draw on.

rectangle
Rectangle

The Rectangle that represents the dimensions of the grab handle glyph.

Examples

The following code example demonstrates using the DrawFocusRectangle method and the Control.Handle property. To run this example, paste the following code in a form. Add two buttons named Button1 and Button2 to the form and ensure all events are connected to their event handlers.

C#
// This method draws a focus rectangle on Button2 using the 
// handle and client rectangle of Button2.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    ControlPaint.DrawFocusRectangle(Graphics.FromHwnd(Button2.Handle), 
        Button2.ClientRectangle);
}

Remarks

A focus rectangle is a dotted rectangle that Windows uses to indicate what control has the current keyboard focus.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10