다음을 통해 공유


방법: Modifiers 및 GenerateMember 속성 사용

Windows Form에 구성 요소를 배치할 때, 디자인 환경에서 GenerateMemberModifiers, 두 개의 속성을 제공합니다. GenerateMember 속성은 Windows Forms 디자이너가 구성 요소에 대한 멤버 변수를 생성하는 경우를 지정합니다. Modifiers 속성은 해당 멤버 변수에 할당된 액세스 한정자입니다. GenerateMember 속성의 값이 false이면 Modifiers 속성의 값은 영향을 미치지 않습니다.

구성 요소가 폼의 멤버인지 여부를 지정합니다.

  1. Visual Studio의 Windows Forms 디자이너에서 폼을 엽니다.

  2. 도구 상자를 열고 폼에서 세 개의 Button 컨트롤을 배치합니다.

  3. 다음 표에 따라 각 Button 컨트롤에 대해 GenerateMemberModifiers 속성을 설정합니다.

    단추 이름 GenerateMember 값 한정자 값
    button1 true private
    button2 true protected
    button3 false 변경 내용 없음
  4. 솔루션을 빌드합니다.

  5. 솔루션 탐색기에서 모든 파일 표시 단추를 클릭합니다.

  6. Form1 노드를 열고 코드 편집기에서 Form1.Designer.vb 또는 Form1.Designer.cs 파일을 엽니다. 이 파일에는 Windows Forms 디자이너에서 내보낸 코드가 포함되어 있습니다.

  7. 세 단추에 대한 선언을 찾습니다. 다음 코드 예에서는 GenerateMemberModifiers 속성으로 지정된 차이를 보여줍니다.

    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 Forms 디자이너는 private(Visual Basic에서는Friend) 한정자를 Panel과 같은 컨테이너 컨트롤에 할당합니다. 기본 UserControl 또는 Form에 컨테이너 컨트롤이 있는 경우, 상속된 컨트롤 및 폼에서 새 자식을 수락하지 않습니다. 솔루션은 기본 컨테이너 컨트롤의 한정자를 protected 또는 public으로 변경하는 것입니다.

참고 항목