VB.net 加載窗體 form2.show() 卸載窗體 me.close()加載窗體和VB沒啥區(qū)別,而卸載就截然不同了。附:VB 加載窗體 form2.show 卸載窗體 unload me
創(chuàng)新互聯(lián)是一家專業(yè)提供互助企業(yè)網(wǎng)站建設,專注與成都網(wǎng)站制作、成都網(wǎng)站建設、HTML5、小程序制作等業(yè)務。10年已為互助眾多企業(yè)、政府機構等服務。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡公司優(yōu)惠進行中。
這是C#的方法,你自己轉(zhuǎn)換為vb.net的,轉(zhuǎn)不了再追問吧。
private?void?button1_Click(object?sender,?EventArgs?e)
{
Form2?frm?=?new?Form2();
frm.Show();
frm.Owner?=?this;
MethodInfo?mi?=?typeof(Application).GetMethod("RunDialog",?BindingFlags.Static?|?BindingFlags.NonPublic);
mi.Invoke(null,?new?object[]?{?frm});
}
直接添加一個MID父窗體或在已有窗體的屬性中找到IsMDIContainer屬性,然后設置為True,然后創(chuàng)建第二個窗體 ,需要加載子窗體的時候:
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子窗體,則創(chuàng)該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子窗體,設為激活?并退出循環(huán)
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
你這個要求實在是不對路子。是思路不對。
應該是將窗體一和窗體二中的控件分別用一個panel裝起來,設為隱含狀態(tài)。都放在主窗體的panel1中。
點擊 窗體一時,第一個panel的Visible=True,第二個panel的Visible=False
點擊 窗體二時,第一個panel的Visible=False,第二個panel的Visible=True
就達到你要的效果了。
窗體不能裝來裝去的。
再有一個方法就是創(chuàng)建自定義控件。那個說起來太麻煩,看看書吧。
加以一個panel用來顯示應用程序的,就是放你那個easycap的,代碼如下
Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Int32, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Int32) As Int32
Private Const WM_SYSCOMMAND As Int32 = H112
Private Const SC_MAXIMIZE As Int32 = HF030
Private Const SC_MINIMIZE As Int32 = HF020
Private Const SC_RESTORE As Int32 = HF120
Public Const SW_HIDE = 0
Public Const SW_SHOW = 5
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Int32, ByVal nCmdShow As Int32) As Int32
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShellExecute(Me.Panel1.Handle, "open", "c:\windows\system32\cmd.exe", Nothing, ".", SW_HIDE)
System.Threading.Thread.Sleep(50)
Dim h As IntPtr = FindWindow(Nothing, "c:\windows\system32\cmd.exe")
ShowWindow(h, SW_HIDE)
SetParent(h, Me.Panel1.Handle) '嵌到panel1內(nèi)
SendMessage(h, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End Sub
把其中的c:\windows\system32\cmd.exe換成你要嵌入的應用程序
Public?Sub?載入窗體()?'在類中公有方法要明確Public
Dim?frm?As?New?Form1?'在Windows應用程序項目中系統(tǒng)隱含生成了一個Form1類的同名對象,其實你直接引用的是隱含的Form1對象,而不是看得著的那個Form1窗口類。
'而在這種工程類型中列表中沒有列出來,應該是沒有的,所以的用代碼生成Form1的實例。
frm.Show()
End?Sub