* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
3.5 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| How to: Render a Visual Style Element | 03/30/2017 |
|
|
a207781b-1baa-4ce9-b788-1e951bd4b5df |
How to: Render a Visual Style Element
The xref:System.Windows.Forms.VisualStyles?displayProperty=nameWithType namespace exposes xref:System.Windows.Forms.VisualStyles.VisualStyleElement objects that represent the Windows user interface (UI) elements supported by visual styles. This topic demonstrates how to use the xref:System.Windows.Forms.VisualStyles.VisualStyleRenderer class to render the xref:System.Windows.Forms.VisualStyles.VisualStyleElement that represents the Log Off and Shut Down buttons of the Start menu.
To render a visual style element
-
Create a xref:System.Windows.Forms.VisualStyles.VisualStyleRenderer and set it to the element you want to draw. Note the use of the xref:System.Windows.Forms.Application.RenderWithVisualStyles%2A?displayProperty=nameWithType property and the xref:System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined%2A?displayProperty=nameWithType method; the xref:System.Windows.Forms.VisualStyles.VisualStyleRenderer.%23ctor%2A constructor will throw an exception if visual styles are disabled or an element is undefined.
[!code-cppSystem.Windows.Forms.VisualStyles.VisualStyleRenderer_Simple#4] [!code-csharpSystem.Windows.Forms.VisualStyles.VisualStyleRenderer_Simple#4] [!code-vbSystem.Windows.Forms.VisualStyles.VisualStyleRenderer_Simple#4]
-
Call the xref:System.Windows.Forms.VisualStyles.VisualStyleRenderer.DrawBackground%2A method to render the element that the xref:System.Windows.Forms.VisualStyles.VisualStyleRenderer currently represents.
[!code-cppSystem.Windows.Forms.VisualStyles.VisualStyleRenderer_Simple#6] [!code-csharpSystem.Windows.Forms.VisualStyles.VisualStyleRenderer_Simple#6] [!code-vbSystem.Windows.Forms.VisualStyles.VisualStyleRenderer_Simple#6]
Compiling the Code
This example requires:
-
A custom control derived from the xref:System.Windows.Forms.Control class.
-
A xref:System.Windows.Forms.Form that hosts the custom control.
-
References to the xref:System?displayProperty=nameWithType, xref:System.Drawing?displayProperty=nameWithType, xref:System.Windows.Forms?displayProperty=nameWithType, and xref:System.Windows.Forms.VisualStyles?displayProperty=nameWithType namespaces.