Question

I have a button that create user on my form. When I click that button, this gets executed:

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

Then I get 3 text boxes and two buttons (save and quit). If I want to add a new text box, what should I do?

Was it helpful?

Solution

I'm not sure if i exactly get your situation, but you can add controls during runtime like so:

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

it could be smart to store a refrence to it so you can access it outside the scope you created it.

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top