我尝试显示多个表单相等,首先声明一个Form类型的变量,然后将变量设置为一个名称,然后显示它但我不能成功。
它没有显示任何新窗口。
Dim from_var As New Form
from_var = inventory_stat_item
With from_var
.MdiParent = main
.StartPosition = FormStartPosition.CenterScreen
.Show()
End With
更新
变量from_var
应具有以下形式名称:(inventory_stat_item | inventory_edit_item | inventory_new_item)
答案 0 :(得分:2)
只要您事先创建和修改Forms
,就应该能够做您想做的事情。像这个快速而肮脏的例子。
Public Class Form1
Dim inventory_stat_item As Form2 = New Form2
Dim inventory_edit_item As Form3 = New Form3
Dim inventory_new_item As Form4 = New Form4
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
showForms(inventory_edit_item)
showForms(inventory_new_item)
showForms(inventory_stat_item)
End Sub
Private Sub showForms(from_var As Form)
With from_var
.MdiParent = Me
.StartPosition = FormStartPosition.CenterScreen
.Show()
End With
End Sub
End Class
答案 1 :(得分:1)
你做不到。每次调用New inventory_stat_item
时,他们都会创建新的对象引用。
您必须拆分代码
调用一次(例如:表单加载时)
Dim from_var As New inventory_stat_item
当用户点击某些内容时调用
With from_var
.MdiParent = Me
.StartPosition = FormStartPosition.CenterScreen
.Show()
End With