* 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.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 |
|
|
|
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
-
In Visual Studio, in the Windows Forms Designer, open your form.
-
Open the Toolbox, and on the form, place three xref:System.Windows.Forms.Button controls.
-
Set the
GenerateMemberandModifiersproperties for each xref:System.Windows.Forms.Button control according to the following table.Button name GenerateMember value Modifiers value button1trueprivatebutton2trueprotectedbutton3falseNo change -
Build the solution.
-
In Solution Explorer, click the Show All Files button.
-
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.
-
Find the declarations for the three buttons. The following code example shows the differences specified by the
GenerateMemberandModifiersproperties.[!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(Friendin 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 toprotectedorpublic.