大家好日子我想问一个问题,因为我想在第二个上创建一个标签,它有我放入第一个表单的textbox1中的文本,我想同时这样做,例如我添加之后要在form2中标记的文本,我将使用相同的方法再次添加另一个标签和文本。我尝试了3个小时,但仍然没有运气。这些代码...提前感谢人员
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim frm2 As New Form2 'Create your Form
Dim lbl As Label = New Label 'Create your Label
lbl.Location = New Point(50, 50) 'Set Label Location
lbl.Text = TextBox1.Text 'Set Label Text
lbl.ForeColor = Color.Black 'Set Label ForeColor
frm2.Controls.Add(lbl) 'Add Label to it
frm2.Show(Me) 'Show Second Form
End Sub
我无意使用form2.show命令,因为我有另一个按钮来显示第二个表单。但是当我删除它时会产生错误。
答案 0 :(得分:2)
在课程中使用此代码..
Private frm2 As New Form2
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim lbl As Label = New Label 'Create your Label
'change the location..
lbl.Location = New Point(50, 50) 'Set Label Location
lbl.Text = TextBox1.Text 'Set Label Text
lbl.ForeColor = Color.Black 'Set Label ForeColor
frm2.Controls.Add(lbl) 'Add Label to it
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
if frm2 IsNot Nothing Then
frm2.Show(Me) 'Show Second Form
End If
End Sub