Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-render-a-visual-style-element.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* 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
2020-09-01 16:26:21 -07:00

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
csharp
vb
cpp
visual themes [Windows Forms], applying to elements of Windows Forms applications
professional appearance [Windows Forms], applying to elements of Windows Forms applications
visual styles [Windows Forms], rendering Windows Forms controls
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

  1. 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]

  2. 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:

See also