重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim pb As New PictureBox pb.Name = "pb" pb.Visible = True Form2.Controls.Add(pb) AddHandler pb.Click, AddressOf pbClick End Sub Private Sub pbClick(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox(True) End Sub 简单的写了代码,希望对你有所帮助
创新互联公司专注于佛坪网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供佛坪营销型网站建设,佛坪网站制作、佛坪网页设计、佛坪网站官网定制、成都小程序开发服务,打造佛坪网络公司原创品牌,更为您提供佛坪网站排名全网营销落地服务。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a As New Form2(TextBox1.Text) '通过参数传递,同1
a.Show()
'form2.show()‘直接启动。同2
End Sub
End Class
Public Class Form2
Sub New(ByVal str As String)
' 此调用是设计器所必需的。
InitializeComponent()
' 在 InitializeComponent() 调用之后添加任何初始化。
TextBox1.Text = str '通过参数传递 1
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'直接在load事件中添加。此两法都可实现。2
' TextBox1.Text = Form1.TextBox1.Text
End Sub
End Class
'1和1一种方法,2和2是一种方法,可以删掉其中一种。
直接添加一个MID父窗体或在已有窗体的属性中找到IsMDIContainer属性,然后设置为True,然后创建第二个窗体 ,需要加载子窗体的时候:
Dim NewMDIChild As New Form2
NewMDIChild.MdiParent = Me
NewMDIChild.Show()
Public Shared Sub CheckMDIChildForm(ByVal MDIForm As Windows.Forms.Form, ByVal MDIChildForm As Windows.Forms.Form, ByVal MDIChildFormName As String)
If MDIForm.MdiChildren.Length 1 Then
'如果没有任何一个MDI子窗体,则创该MDI子窗体的窗体实例
Dim MDIChildFrm As Windows.Forms.Form = MDIChildForm ' 定义MDI子窗体
MDIChildFrm.MdiParent = MDIForm '指定父窗体
MDIChildFrm.Show() '打开窗体
Exit Sub
Else
Dim x As Integer
Dim frmyn As Boolean
For x = 0 To (MDIForm.MdiChildren.Length) - 1
Dim tempChild As Windows.Forms.Form = CType(MDIForm.MdiChildren(x), Windows.Forms.Form)
If tempChild.Name = MDIChildFormName Then
'检测到有该MDI子窗体,设为激活 并退出循环
frmyn = True
tempChild.BringToFront()
Exit For
Else
frmyn = False
End If
Next
If Not frmyn Then
'在打开的窗体中没检测到则新建
Dim MDIChildFrm As Windows.Forms.Form = MDIChildForm ' 定义MDI子窗体
MDIChildFrm.MdiParent = MDIForm '指定父窗体
MDIChildFrm.Show() '打开窗体
End If
End If
End Sub
打开Visual Studio,点击文件→新建项,选择“窗体”,在文件名那里输入Form2.vb就得了