vb.net - 在 Sub 运行时显示沙漏或请稍候消息

标签 vb.net

我的表单上运行了以下子程序。子程序运行可能需要一段时间,因此我想将光标更改为沙漏并在代码运行时显示请稍候消息。这是我的程序:

Public Sub GoToSheets(sheetName As String)

'This sub is used to open the workbook on the selected sheet.
'This checks to see if Excel workbook is opened, if not it
'opens Excel, the workbook and then the selected sheet. If the workbook is
'opened, it goes to the selected sheet.

'@param sheetName, sheet to be displayed

Try
    'get an existing excel.application object
    xlApp = CType(GetObject(, "Excel.Application"), Application)
Catch ex As Exception
    'no existing excel.application object - create a new one

    xlApp = New Excel.Application

End Try

Dim xlWBName As String = "2011.1004.Compensation Template"
Dim xlBookPath As String = Path.Combine(Directory.GetCurrentDirectory())

xlApp.Visible = True

Try
    'get the opened workbook
    xlBook = xlApp.Workbooks(xlWBName & ".xlsx")
Catch ex As Exception
    'open it
    xlBook = xlApp.Workbooks.Open(xlBookPath & "\" & xlWBName & ".xlsx")
End Try

Try

    xlSheet = CType(CType(xlBook.Sheets("summarySheet"), Excel.Worksheet), Excel.Worksheet)
    Dim strChckRange As String = xlSheet.Range("A2").Value

    If strChckRange Is Nothing Then

        Dim frmClientInfo As New frmClientInformation
        frmClientInfo.ShowDialog()

        closeXLApp()

    Else


        xlSheet = CType(CType(xlBook.Sheets(sheetName), Excel.Worksheet), Excel.Worksheet)


        'close the navigation instance on the welcome page
        frmNavigation.Close()
        'activate requested sheet
        xlSheet.Activate()
        'display as dashboard
        DashboardView()

        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)

        GC.Collect()
        GC.WaitForPendingFinalizers()
        GC.Collect()
        GC.WaitForPendingFinalizers()

        frmWelcomePage.Hide()
        chkForm()

    End If

Catch ex As Exception

End Try

结束子

我已经对此进行了一些研究,但到目前为止还没有针对 Visual Basic 的研究。

最佳答案

我建议创建一个 PleaseWaitForm,上面有 Please Wait... 消息标签,然后将表单显示为无模式,将光标更改为沙漏,执行 Excel 工作,将光标更改回默认值并隐藏 PleaseWaitForm

Dim pleaseWait As New PleaseWaitForm
pleaseWait.Show()

' Set cursor as hourglass
Cursor.Current = Cursors.WaitCursor

Application.DoEvents

' Execute your GoToSheets method here

' Set cursor as default arrow
Cursor.Current = Cursors.Default

' Hide the please wait form
pleaseWait.Hide()

关于vb.net - 在 Sub 运行时显示沙漏或请稍候消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20156933/

相关文章:

vb.net - 在没有选中/未选中关键字支持的情况下覆盖 VB 中的 GetHashCode?

c# - LINQ - 在父子层次结构中全选

php - 连接到 wampserver MySQL 在 PHP 中有效,但在 vb.NET 中无效

mysql - 解决多基表不支持动态SQL生成

vb.net - DataGridView 转 CSV 文件

mysql - DataGridView对应的Column...用MySQL

c# - 2 个简单快速的 C# 特定 Visual Studio 问题?

Javascript 调用 vb.net 中的 pageMethod 不起作用

c# - "Lazy"MVC5 Razor 执行 - ASP.NET(优化)

c++ - 将包含字符串数组和整数数组的结构传递给 C++ DLL