VisualStyleRenderer.GetPartSize Method

Definition

Returns the value of the specified size property of the current visual style part.

Overloads

GetPartSize(IDeviceContext, ThemeSizeType)

Returns the value of the specified size property of the current visual style part.

GetPartSize(IDeviceContext, Rectangle, ThemeSizeType)

Returns the value of the specified size property of the current visual style part using the specified drawing bounds.

GetPartSize(IDeviceContext, ThemeSizeType)

Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs

Returns the value of the specified size property of the current visual style part.

C#
public System.Drawing.Size GetPartSize(System.Drawing.IDeviceContext dc, System.Windows.Forms.VisualStyles.ThemeSizeType type);

Parameters

dc
IDeviceContext

The IDeviceContext this operation will use.

type
ThemeSizeType

One of the ThemeSizeType values that specifies which size value to retrieve for the part.

Returns

A Size that contains the size specified by the type parameter for the current visual style part.

Exceptions

dc is null.

prop is not one of the ThemeSizeType values.

Examples

The following code example demonstrates how to use the GetPartSize(IDeviceContext, ThemeSizeType) method in a custom control to get the sizes of a window title bar, Close button, borders, and sizing handle specified by the visual style. These sizes are used to calculate the sizes of the Rectangle objects used to draw the VisualStyleElement objects that represent these window parts. This code example is part of a larger example provided for the VisualStyleRenderer class overview.

C#
// Get the sizes and offsets for the window parts as specified  
// by the visual style.
private void GetPartDetails()
{
    // Do nothing further if visual styles are not enabled.
    if (!Application.RenderWithVisualStyles)
    {
        return;
    }

    using (Graphics g = this.CreateGraphics())
    {
        // Get the size and offset of the close button.
        if (SetRenderer(windowElements["windowClose"]))
        {
            closeButtonSize =
                renderer.GetPartSize(g, ThemeSizeType.True);
            closeButtonOffset =
                renderer.GetPoint(PointProperty.Offset);
        }

        // Get the height of the window caption.
        if (SetRenderer(windowElements["windowCaption"]))
        {
            captionHeight = renderer.GetPartSize(g,
                ThemeSizeType.True).Height;
        }

        // Get the thickness of the left, bottom, 
        // and right window frame.
        if (SetRenderer(windowElements["windowLeft"]))
        {
            frameThickness = renderer.GetPartSize(g,
                ThemeSizeType.True).Width;
        }

        // Get the size of the resizing gripper.
        if (SetRenderer(windowElements["statusGripper"]))
        {
            gripperSize = renderer.GetPartSize(g,
                ThemeSizeType.True);
        }
    }
}

Remarks

Typically, only the True and Minimum values should be used for the type parameter of this method.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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

GetPartSize(IDeviceContext, Rectangle, ThemeSizeType)

Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs

Returns the value of the specified size property of the current visual style part using the specified drawing bounds.

C#
public System.Drawing.Size GetPartSize(System.Drawing.IDeviceContext dc, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.ThemeSizeType type);

Parameters

dc
IDeviceContext

The IDeviceContext this operation will use.

bounds
Rectangle

A Rectangle that contains the area in which the part will be drawn.

type
ThemeSizeType

One of the ThemeSizeType values that specifies which size value to retrieve for the part.

Returns

A Size that contains the size specified by the type parameter for the current visual style part.

Exceptions

dc is null.

prop is not one of the ThemeSizeType values.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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