我希望了解如何以编程方式向我的应用添加新表单&然后在新表格中添加一个图片框,文本框和一个按钮?
我可以在当前表单上添加新按钮,新表单或新图片框,但我似乎无法弄清楚如何向我的应用程序添加新表单,然后放置图片框和文本框以及新表格上的按钮。
我错过了什么?
'Form2
Dim form2 As New Form
form2.Size = New System.Drawing.Size(500, 500)
form2.Show()
Dim picturebox1 As New PictureBox()
Dim Textbox1 As New TextBox()
Dim Button1 As New Button()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'PICTURE BOX PROPERTIES
'
picturebox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
picturebox1.Location = New System.Drawing.Point(11, 12)
picturebox1.Name = "PictureBox1"
picturebox1.Size = New System.Drawing.Size(365, 124)
picturebox1.TabIndex = 0
picturebox1.TabStop = False
picturebox1.Show()
'TEXTBOX PROPERTIES
Textbox1.Location = New System.Drawing.Point(12, 142)
Textbox1.Name = "TextBox1"
Textbox1.Size = New System.Drawing.Size(364, 20)
Textbox1.TabIndex = 1
Textbox1.Show()
'BUTTON PROPERTIES
Button1.Location = New System.Drawing.Point(128, 172)
Button1.Name = "Button1"
Button1.Size = New System.Drawing.Size(95, 24)
Button1.TabIndex = 2
Button1.Text = "Submit"
Button1.Show()
Me.Controls.Add(picturebox1)
Me.Controls.Add(Textbox1)
Me.Controls.Add(Button1)
答案 0 :(得分:3)
你应该尝试:
form2.Controls.Add(picturebox1)
form2.Controls.Add(Textbox1)
form2.Controls.Add(Button1)
这将显示Control
中的form2
。