Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-use-the-modifiers-and-generatemember-properties.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.3 KiB

title, ms.date, dev_langs, f1_keywords, helpviewer_keywords, ms.assetid
title ms.date dev_langs f1_keywords helpviewer_keywords ms.assetid
How to: Use the Modifiers and GenerateMember Properties 03/30/2017
csharp
vb
Designer_GenerateMember
Designer_Modifiers
base forms
inheritance [Windows Forms], forms
inherited forms [Windows Forms], Windows Forms
inherited forms
form inheritance
Windows Forms, inheritance
3381a5e4-e1a3-44e2-a765-a0b758937b85

How to: Use the Modifiers and GenerateMember Properties

When you place a component on a Windows Form, two properties are provided by the design environment: GenerateMember and Modifiers. The GenerateMember property specifies when the Windows Forms Designer generates a member variable for a component. The Modifiers property is the access modifier assigned to that member variable. If the value of the GenerateMember property is false, the value of the Modifiers property has no effect.

Specify whether a component is a member of the form

  1. In Visual Studio, in the Windows Forms Designer, open your form.

  2. Open the Toolbox, and on the form, place three xref:System.Windows.Forms.Button controls.

  3. Set the GenerateMember and Modifiers properties for each xref:System.Windows.Forms.Button control according to the following table.

    Button name GenerateMember value Modifiers value
    button1 true private
    button2 true protected
    button3 false No change
  4. Build the solution.

  5. In Solution Explorer, click the Show All Files button.

  6. Open the Form1 node, and in the Code Editor,open the Form1.Designer.vb or Form1.Designer.cs file. This file contains the code emitted by the Windows Forms Designer.

  7. Find the declarations for the three buttons. The following code example shows the differences specified by the GenerateMember and Modifiers properties.

    [!code-csharpSystem.Windows.Forms.GenerateMember#3] [!code-vbSystem.Windows.Forms.GenerateMember#3]

    [!code-csharpSystem.Windows.Forms.GenerateMember#2] [!code-vbSystem.Windows.Forms.GenerateMember#2]

Note

By default, the Windows Forms Designer assigns the private (Friend in Visual Basic) modifier to container controls like xref:System.Windows.Forms.Panel. If your base xref:System.Windows.Forms.UserControl or xref:System.Windows.Forms.Form has a container control, it will not accept new children in inherited controls and forms. The solution is to change the modifier of the base container control to protected or public.

See also