VB 2008 - WaitCursor does not work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • desertavataraz
    New Member
    • Jan 2009
    • 14

    VB 2008 - WaitCursor does not work

    I am trying in Visual Basic 2008 to make the wait cursor appear as a file is opening, in case it is a long file, and this is the code, but it does not work:
    Code:
            Dim openFile1 As New OpenFileDialog()
                If DiscardChanges() Then
                    Me.UseWaitCursor = True
                    ' Initialize the OpenFileDialog to look for RTF files.
                    openFile1.DefaultExt = "*.rtf"
                    openFile1.Filter = "RTF Files|*.rtf|Doc Files|*.DOC|" & _
                    "Text Files|*.txt|All Flies|*.*"
                    ' Determine whether the user selected a file from the OpenFileDialog.
                    If (openFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
                        And (openFile1.FileName.Length > 0) Then
                        ' Load the contents of the file into the RichTextBox.
                        RichTextBox1.LoadFile(openFile1.FileName, _
                            RichTextBoxStreamType.RichText)
                        RichTextBox1.Modified = False
                        fName = openFile1.FileName
                    End If
                End If
                Me.UseWaitCursor = False
    Last edited by Frinavale; May 25 '09, 02:41 PM. Reason: Fixed code tags. Please poste code in [code] [/code] tags.
  • Salmenmikko
    New Member
    • Jun 2009
    • 2

    #2
    WaitCursor

    Hi desertavataraz!

    I'm a C# coder and I'm not sure about the whole UseWaitCursor-business, but how about this:

    Add a line changing your current cursor to wait cursor just before doing the operation that might take long and changing it back to dafault after it's done.

    Like this(example just sleeps 5 secs to simulate long file open):
    Code:
            Me.Cursor = Cursors.WaitCursor
            Threading.Thread.Sleep(5000)
            Me.Cursor = Cursors.Default
    If I were you, I'd place the cursor change to right before call to
    Code:
    RichTextBox1.LoadFile
    and change it back right after it.

    HTH,
    salmenmikko
    Last edited by Curtis Rutland; Jun 29 '09, 02:33 PM. Reason: Please use [CODE] tags when you post code.

    Comment

    • desertavataraz
      New Member
      • Jan 2009
      • 14

      #3
      Thanks for the reply

      That looks like a very good suggestion, I will try it out when I get back from vacation . .. Thanks!

      Comment

      • Dissymmetry
        New Member
        • Jun 2009
        • 1

        #4
        The UseWaitCursor applies to a specific control and all its child controls. This means that the cursor will change to a wait cursor when it is over that control or control group only. You would call it such ...

        Code:
        Me.UseWaitCursor = True
        Threading.Thread.Sleep(5000)
        Me.UseWaitCursor = False
        It only works, however, when that control or control group is actually processing code. This means you can't just set the cursor and end code execution waiting for input from another source or control to clear the cursor. It may work that way if you set Application.Use WaitCursor = True, but then you may as well use the other code.

        Comment

        Working...