扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
尽量丢掉vb6的习惯,注意对象的作用域及垃圾回收机制,为对象设定适当的范围,如全局对象下面给个示例(从sub main启动):public module sample public sub main() dim frm as new from1("sample form") frm.show windows.forms.application.run() end subend module public class form1 inherts windows.forms.form private btnnew as new windows.forms.button private btnclose as new windows.forms.button public sub new(byval text as string) me.text=text btnnew.text="new form" btnclose.text="exit" btnnew.location=new drawing.point(30,10) btnclose.location=new drawing.point(30,35) me.controls.add(btnnew) me.controls.add(btnclose) addhandler btnnew.click,addressof btnnew_click addhandler btnclose.click,addressof btnclose_click end sub private sub btnnew_click(byval o as object,byval e as eventargs) me.close() dim newform as new form1("new sample form") newform.show() end sub private sub btnclose_click(byval o as object,byval e as eventargs) windows.forms.application.exit() end subend class
坚守“ 做人真诚 · 做事靠谱 · 口碑至上 · 高效敬业 ”的价值观,专业网站建设服务10余年为成都建筑动画小微创业公司专业提供成都企业网站定制营销网站建设商城网站建设手机网站建设小程序网站建设网站改版,从内容策划、视觉设计、底层架构、网页布局、功能开发迭代于一体的高端网站建设服务。
直接添加一个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
Public Class Form1
Dim I As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
I = I + 1
If I = 10 Then Me.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Hide()
End Sub
End Class
你可以先隐藏窗体 让他加载完 再显示出来 如上代码 如果还不够时间 可以适当增加
VB.net 加载窗体 form2.show() 卸载窗体 me.close()加载窗体和VB没啥区别,而卸载就截然不同了。附:VB 加载窗体 form2.show 卸载窗体 unload me
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流