Connecting Tech Pros Worldwide Forums | Help | Site Map

VB 2008 - WaitCursor does not work

Newbie
 
Join Date: Jan 2009
Posts: 13
#1: May 25 '09
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:
Expand|Select|Wrap|Line Numbers
  1.         Dim openFile1 As New OpenFileDialog()
  2.             If DiscardChanges() Then
  3.                 Me.UseWaitCursor = True
  4.                 ' Initialize the OpenFileDialog to look for RTF files.
  5.                 openFile1.DefaultExt = "*.rtf"
  6.                 openFile1.Filter = "RTF Files|*.rtf|Doc Files|*.DOC|" & _
  7.                 "Text Files|*.txt|All Flies|*.*"
  8.                 ' Determine whether the user selected a file from the OpenFileDialog.
  9.                 If (openFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
  10.                     And (openFile1.FileName.Length > 0) Then
  11.                     ' Load the contents of the file into the RichTextBox.
  12.                     RichTextBox1.LoadFile(openFile1.FileName, _
  13.                         RichTextBoxStreamType.RichText)
  14.                     RichTextBox1.Modified = False
  15.                     fName = openFile1.FileName
  16.                 End If
  17.             End If
  18.             Me.UseWaitCursor = False

Newbie
 
Join Date: Jun 2009
Posts: 2
#2: Jun 29 '09

re: VB 2008 - WaitCursor does not work


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):
Expand|Select|Wrap|Line Numbers
  1.         Me.Cursor = Cursors.WaitCursor
  2.         Threading.Thread.Sleep(5000)
  3.         Me.Cursor = Cursors.Default
If I were you, I'd place the cursor change to right before call to
Expand|Select|Wrap|Line Numbers
  1. RichTextBox1.LoadFile
and change it back right after it.

HTH,
salmenmikko
Newbie
 
Join Date: Jan 2009
Posts: 13
#3: Jun 30 '09

re: VB 2008 - WaitCursor does not work


That looks like a very good suggestion, I will try it out when I get back from vacation . .. Thanks!
Newbie
 
Join Date: Jun 2009
Posts: 1
#4: Jun 30 '09

re: VB 2008 - WaitCursor does not work


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 ...

Expand|Select|Wrap|Line Numbers
  1. Me.UseWaitCursor = True
  2. Threading.Thread.Sleep(5000)
  3. 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.UseWaitCursor = True, but then you may as well use the other code.
Reply

Tags
wait cursor