1

我试图显示多个表单相等,首先声明一个 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)

4

2 回答 2

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
于 2012-08-06T02:10:15.673 回答
1

你不能这样做。您调用的每个人New inventory_stat_item都创建了新的对象引用。

您必须拆分代码

调用一次(例如:表单加载时)

Dim from_var As New inventory_stat_item

当用户点击某物时调用

With from_var
    .MdiParent = Me
    .StartPosition = FormStartPosition.CenterScreen
    .Show()
End With
于 2012-08-06T02:02:41.070 回答