这段代码不能实现子窗体
如题。。
在VB6里面是好的,但是到了VB.NET里面就不行了。。。。
到底怎么的呢?
Public Class Sheet1
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Private Declare Auto Function FindWindow Lib "user32" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Integer
Dim xlap As New Excel.Application
Private Sub Sheet1_Startup() Handles Me.Startup
End Sub
Private Sub Sheet1_Shutdown() Handles Me.Shutdown
End Sub
Dim fm As New ExcelWorkbook1.Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
fm.Show()
SetParent(fm.Handle, xlap.Hwnd)
End Sub
End Class
[解决办法]
给点代码参考下 其中PalletPrint为子窗体ID
Private Sub PalletPrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PalletPrintToolStripMenuItem.Click
For Each Childform As Form In Me.MdiChildren
Childform.Close()
Next
ShowForm(Me, PalletPrint)
Me.Hide()
End Sub
Public Sub ShowForm(ByVal MainForm As Form, ByVal ChildForm As Form)
For Each _ChildForm As Form In ChildForm.MdiChildren
_ChildForm.Close()
Next
ChildForm.MdiParent = MainForm.Container
ChildForm.Show()
'With ChildForm
' .Top = MainForm.Top
' .Left = MainForm.Left
' .Width = MainForm.Width
' .Height = MainForm.Height
'End With
End Sub