方法: Modifiers プロパティおよび GenerateMember プロパティを使用する
コンポーネントを Windows フォームに配置すると、デザイン環境によって、GenerateMember
と Modifiers
の 2 つのプロパティが提供されます。 GenerateMember
プロパティでは、Windows フォーム デザイナーによってコンポーネントのメンバー変数が生成されるタイミングを指定します。 Modifiers
プロパティは、そのメンバー変数に割り当てられたアクセス修飾子です。 GenerateMember
プロパティの値が false
の場合、Modifiers
プロパティの値は無効です。
コンポーネントがフォームのメンバーであるかどうかを指定する
Visual Studio の Windows フォーム デザイナーで、フォームを開きます。
ツールボックスを開き、フォームに 3 つの Button コントロールを配置します。
次の表に従って、各 Button コントロールの
GenerateMember
プロパティとModifiers
プロパティを設定します。ボタン名 GenerateMember の値 Modifiers の値 button1
true
private
button2
true
protected
button3
false
変更なし ソリューションをビルドします。
ソリューション エクスプローラーで、 [すべてのファイルを表示] ボタンをクリックします。
Form1 ノードを開き、コード エディターで、Form1.Designer.vb ファイルまたは Form1.Designer.cs ファイルを開きます。 このファイルには、Windows フォーム デザイナーによって出力されるコードが含まれています。
3 つのボタンの宣言を見つけます。 次のコード例は、
GenerateMember
プロパティとModifiers
プロパティによって指定された違いを示します。private void InitializeComponent() { // button3 is declared in a local scope, because // its GenerateMember property is false. System.Windows.Forms.Button button3; this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); button3 = new System.Windows.Forms.Button();
Private Sub InitializeComponent() ' button3 is declared in a local scope, because ' its GenerateMember property is false. Dim button3 As System.Windows.Forms.Button Me.button1 = New System.Windows.Forms.Button() Me.button2 = New System.Windows.Forms.Button() button3 = New System.Windows.Forms.Button()
// The Modifiers property for button1 is "private". private Button button1; // The Modifiers property for button2 is "protected". protected Button button2; // button3 is not a member, because // its GenerateMember property is false.
' The Modifiers property for button1 is "Private". Private button1 As Button ' The Modifiers property for button2 is "Protected". Protected button2 As Button ' button3 is not a member, because ' its GenerateMember property is false.
注意
既定では、Windows フォーム デザイナーによって、private
(Visual Basic では Friend
) 修飾子が Panel のようなコンテナー コントロールに割り当てられます。 ベースの UserControl または Form にコンテナー コントロールがある場合は、継承されたコントロールやフォームによって新しい子が受け取られることはありません。 解決するには、ベース コンテナー コントロールの修飾子を protected
または public
に変更します。
関連項目
.NET Desktop feedback
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示