折叠面板后添加新文本框
Posted
技术标签:
【中文标题】折叠面板后添加新文本框【英文标题】:Add new textbox after collapsing panel 【发布时间】:2013-08-04 22:40:35 【问题描述】:我有一个在我的表单上创建用户的按钮。当我点击那个按钮时,它会被执行:
Me.SplitContainer1.Panel1Collapsed = True
Me.BtnSave.Tag = "addNew"
Me.txtUserName.Text = ""
Me.txtPassword.Text = ""
Me.txtRole.Text = ""
然后我得到 3 个文本框和两个按钮(保存和退出)。如果我想添加一个新的文本框,我应该怎么做?
【问题讨论】:
【参考方案1】:我不确定我是否完全了解您的情况,但您可以在运行时添加控件,如下所示:
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
将引用存储到它可能很聪明,这样您就可以在创建它的范围之外访问它。
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
【讨论】:
以上是关于折叠面板后添加新文本框的主要内容,如果未能解决你的问题,请参考以下文章