VisualStyleRenderer.GetPartSize 方法     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回当前视觉样式部件的指定大小属性的值。
重载
| GetPartSize(IDeviceContext, ThemeSizeType) | 返回当前视觉样式部件的指定大小属性的值。 | 
| GetPartSize(IDeviceContext, Rectangle, ThemeSizeType) | 使用指定的绘制边界返回当前视觉样式部件的指定大小属性的值。 | 
GetPartSize(IDeviceContext, ThemeSizeType)
- Source:
- VisualStyleRenderer.cs
- Source:
- VisualStyleRenderer.cs
- Source:
- VisualStyleRenderer.cs
返回当前视觉样式部件的指定大小属性的值。
public:
 System::Drawing::Size GetPartSize(System::Drawing::IDeviceContext ^ dc, System::Windows::Forms::VisualStyles::ThemeSizeType type);public System.Drawing.Size GetPartSize(System.Drawing.IDeviceContext dc, System.Windows.Forms.VisualStyles.ThemeSizeType type);member this.GetPartSize : System.Drawing.IDeviceContext * System.Windows.Forms.VisualStyles.ThemeSizeType -> System.Drawing.SizePublic Function GetPartSize (dc As IDeviceContext, type As ThemeSizeType) As Size参数
此操作将使用的 IDeviceContext。
- type
- ThemeSizeType
ThemeSizeType 值之一,指定为部件检索哪个大小值。
返回
一个 Size,它包含由 type 参数为当前视觉样式部件所指定的大小。
例外
              dc 为 null。
              prop 不是 ThemeSizeType 值之一。
示例
下面的代码示例演示如何在自定义控件中使用 GetPartSize(IDeviceContext, ThemeSizeType) 方法获取窗口标题栏、 “关闭 ”按钮、边框和视觉样式指定的大小控点的大小。 这些大小用于计算用于绘制表示这些窗口部件的对象VisualStyleElement的对象的大小Rectangle。 此代码示例是为类概述提供的更大示例的 VisualStyleRenderer 一部分。
    // 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;
        }
        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);
        }
    }
// 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);
        }
    }
}
' Get the sizes and offsets for the window parts as specified 
' by the visual style.
Private Sub GetPartDetails()
    ' Do nothing further if visual styles are not enabled.
    If Not Application.RenderWithVisualStyles Then
        Return
    End If
    Using g As Graphics = Me.CreateGraphics()
        ' Get the size and offset of the close button.
        If SetRenderer(windowElements("windowClose")) Then
            closeButtonSize = _
                renderer.GetPartSize(g, ThemeSizeType.True)
            closeButtonOffset = _
                renderer.GetPoint(PointProperty.Offset)
        End If
        ' Get the height of the window caption.
        If SetRenderer(windowElements("windowCaption")) Then
            captionHeight = renderer.GetPartSize(g, _
                ThemeSizeType.True).Height
        End If
        ' Get the thickness of the left, bottom, and right 
        ' window frame.
        If SetRenderer(windowElements("windowLeft")) Then
            frameThickness = renderer.GetPartSize(g, _
                ThemeSizeType.True).Width
        End If
        ' Get the size of the resizing gripper.
        If SetRenderer(windowElements("statusGripper")) Then
            gripperSize = renderer.GetPartSize(g, _
                ThemeSizeType.True)
        End If
    End Using
End Sub
注解
通常,仅 True 应将 和 Minimum 值用于 type 此方法的 参数。
适用于
GetPartSize(IDeviceContext, Rectangle, ThemeSizeType)
- Source:
- VisualStyleRenderer.cs
- Source:
- VisualStyleRenderer.cs
- Source:
- VisualStyleRenderer.cs
使用指定的绘制边界返回当前视觉样式部件的指定大小属性的值。
public:
 System::Drawing::Size GetPartSize(System::Drawing::IDeviceContext ^ dc, System::Drawing::Rectangle bounds, System::Windows::Forms::VisualStyles::ThemeSizeType type);public System.Drawing.Size GetPartSize(System.Drawing.IDeviceContext dc, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.ThemeSizeType type);member this.GetPartSize : System.Drawing.IDeviceContext * System.Drawing.Rectangle * System.Windows.Forms.VisualStyles.ThemeSizeType -> System.Drawing.SizePublic Function GetPartSize (dc As IDeviceContext, bounds As Rectangle, type As ThemeSizeType) As Size参数
此操作将使用的 IDeviceContext。
- type
- ThemeSizeType
ThemeSizeType 值之一,指定为部件检索哪个大小值。
返回
一个 Size,它包含由 type 参数为当前视觉样式部件所指定的大小。
例外
              dc 为 null。
              prop 不是 ThemeSizeType 值之一。