直接添加一個MID父窗體或在已有窗體的屬性中找到IsMDIContainer屬性,然后設置為True,然后創(chuàng)建第二個窗體 ,需要加載子窗體的時候:
創(chuàng)新互聯(lián)建站專注于自貢網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供自貢營銷型網(wǎng)站建設,自貢網(wǎng)站制作、自貢網(wǎng)頁設計、自貢網(wǎng)站官網(wǎng)定制、小程序設計服務,打造自貢網(wǎng)絡公司原創(chuàng)品牌,更為您提供自貢網(wǎng)站排名全網(wǎ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
form2 窗體在vb.net中為類的形式存在,必須先定義該類的實例子方可引用.
dim f1 as new form2
f2.show
加以一個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換成你要嵌入的應用程序
如果我沒理解錯:
Form1(下窗體) Form2(上窗體)
且已在Form1中聲明了Form2
那不直接就可以在Form2中控制Form1的控件的值咯?
哦,明白了!
你是想不動Form2找到值后就高亮顯示出來查詢結果?
那還不簡單,在Form2里邊加上me.Topmast=True讓Form2位于頂層
前提是你的Form1里的文本控件可實現(xiàn)選擇效果,如RichTextBox,
在Form2中找到結果后寫入 Form1.RichTextBox1.Select( start , Length),選則結果文本就可以高亮了,這樣就實現(xiàn)了Form2 不關閉,且Form1 顯示結果。
你這個要求實在是不對路子。是思路不對。
應該是將窗體一和窗體二中的控件分別用一個panel裝起來,設為隱含狀態(tài)。都放在主窗體的panel1中。
點擊 窗體一時,第一個panel的Visible=True,第二個panel的Visible=False
點擊 窗體二時,第一個panel的Visible=False,第二個panel的Visible=True
就達到你要的效果了。
窗體不能裝來裝去的。
再有一個方法就是創(chuàng)建自定義控件。那個說起來太麻煩,看看書吧。