经过多次尝试和磨难,我终于能够从一个 winform 按钮最小化我的应用程序。该代码完美运行:
Private Sub btnMinWindow_Click(sender As Object, e As EventArgs) Handles btnMinWindow.Click
'This procedure runs when the btnMinWindow is clicked.
'The procedure minizmizes the form and Excel.
Dim WB As Excel.Workbook = CType(Globals.ThisWorkbook.Application.ActiveWorkbook, Excel.Workbook)
Me.WindowState = FormWindowState.Minimized
WB.Application.WindowState = XlWindowState.xlMinimized
End Sub
所以当然,最小化的东西最终需要最大化。所以我假设我所要做的就是正确的相同代码只使用 xlMaximized。当然,我的假设是错误的。这是我的代码:
Private Sub btnMinEmployeeDashboard_Click(sender As Object, e As EventArgs) Handles btnMinEmployeeDashboard.Click
'This procedure runs when the btnEmployeeDashboard button is clicked.
Dim WB As Excel.Workbook = CType(Globals.ThisWorkbook.Application.ActiveWorkbook, Excel.Workbook)
WB.Application.WindowState = XlWindowState.xlMaximized
WB.Sheets("employeeBoard").Select()
Me.Close()
End Sub
代码关闭表单,选择工作表,但它没有最大化我的窗口。我认为我必须做的是使“已经最小化”的变量(在范围内)可用于按钮 _Click 处理程序并使用它而不是声明一个新变量。不幸的是,如果是这样的话,我不知道该怎么做。