用于调用其他 exe 充当 MDI 子窗体的 VB.NET 示例代码?是否可以?

发布于 2024-10-27 08:50:08 字数 854 浏览 7 评论 0原文

好的,这是场景。
1.我创建了一个项目,其中有 1 个名为 form1.exe 的表单
2.我还创建了一个具有 1 个 MDI 表单的项目。
在此 MDI 表格中。我想调用“form1.exe”,其行为类似于 MDI 表单子项。 我尝试过使用这段代码:

Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndParent As IntPtr) As IntPtr
End Function


Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
    Dim myProcess As Process = New Process()
    myProcess.StartInfo.FileName = "D:\tesVB.exe"
    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
    myProcess.Start()
    myProcess.WaitForInputIdle()
    SetParent(myProcess.MainWindowHandle, Me.Handle)
    myProcess.WaitForExit()
End Sub

上面的代码可以工作,但是新的子表单(form1.exe)的行为并不像它应该的那样!当我最大化或最小化它时。它的行为不像 MDI 子窗体。
谁能给我另一个更好的示例代码?谢谢之前。

ok here is the scenario.
1. i've create a project that has 1 form named form1.exe
2. i've also create a project that has 1 MDI form.
in this MDI Form. i'would like to call "form1.exe" act like / behave like MDI Form child.
i've tried using this code :

Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndParent As IntPtr) As IntPtr
End Function


Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
    Dim myProcess As Process = New Process()
    myProcess.StartInfo.FileName = "D:\tesVB.exe"
    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
    myProcess.Start()
    myProcess.WaitForInputIdle()
    SetParent(myProcess.MainWindowHandle, Me.Handle)
    myProcess.WaitForExit()
End Sub

Above code is worked but that new child form(form1.exe) doesn't act like it should be! When i maximized or minimized it. it don't act like MDI Child Form.
Can anyone give me another better example code ? thx before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风情万种。 2024-11-03 08:50:08

哈哈哈……我自己发现的。希望这个解决方案对其他人有好处。

Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click

    Dim eAssembly As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("D:\form1.exe")
    Dim eForm As Form = eAssembly.CreateInstance("form1.Form1", True)
    Me.AddOwnedForm(eForm)
    eForm.MdiParent = Me
    eForm.Show()

End Sub

hahaha.... found it my self. hope this solution would be good for others.

Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click

    Dim eAssembly As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("D:\form1.exe")
    Dim eForm As Form = eAssembly.CreateInstance("form1.Form1", True)
    Me.AddOwnedForm(eForm)
    eForm.MdiParent = Me
    eForm.Show()

End Sub
煮酒 2024-11-03 08:50:08
Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click

    Dim eAssembly As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("D:\form1.exe")
    Dim eForm As Form = eAssembly.CreateInstance("form1.Form1", True)
    Me.AddOwnedForm(eForm)
    eForm.MdiParent = Me
    eForm.Show()

End Sub

运行时错误

eform 是一个表单,eAssembly.CreateInstance("form1.Form1", True) 返回一个对象

Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click

    Dim eAssembly As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("D:\form1.exe")
    Dim eForm As Form = eAssembly.CreateInstance("form1.Form1", True)
    Me.AddOwnedForm(eForm)
    eForm.MdiParent = Me
    eForm.Show()

End Sub

Runtime error

eform is a form and eAssembly.CreateInstance("form1.Form1", True) returns an object

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文