2013-08-03 6 views
-1

내 양식에 사용자를 만드는 버튼이 있습니다. 버튼을 클릭하면 다음과 같이 실행됩니다.패널 축소 후 새 텍스트 상자 추가

Me.SplitContainer1.Panel1Collapsed = True 
Me.BtnSave.Tag = "addNew" 
Me.txtUserName.Text = "" 
Me.txtPassword.Text = "" 
Me.txtRole.Text = "" 

그러면 3 개의 텍스트 상자와 2 개의 버튼 (저장 및 종료)이 표시됩니다. 새 텍스트 상자를 추가하려면 어떻게해야합니까? 내가 정확하게 상황을 얻는 경우에

답변

0

는 잘 모르겠어요,하지만 당신과 같이 런타임에 컨트롤을 추가 할 수 있습니다

Dim txtNewTextBox As TextBox = New TextBox() 'create and initialize 
txtNewTextBox.Parent = SplitContainer1.Panel1 'set its parent 
txtNewTextBox.Location = New Point(12, 50) 'location based on the parent location 

는 그렇게 당신이 외부에서 액세스 할 수 그것에에 refrence를 저장하는 스마트 될 수있다 당신이 만든 범위.

Public Class Form1 
    Dim txtNewTextBoxRef As TextBox = Nothing 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     Dim txtNewTextBox As TextBox = New TextBox() 
     txtNewTextBox.Parent = SplitContainer1.Panel1 
     txtNewTextBox.Location = New Point(12, 50) 
     txtNewTextBoxRef = txtNewTextBox 
    End Sub 

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 
     MsgBox("txtNewTextBox.text = " & txtNewTextBoxRef.Text) 
    End Sub 
End Class