Connecting Tech Pros Worldwide Help | Site Map

VB 2008 - WaitCursor does not work

  #1  
Old May 25th, 2009, 03:40 PM
Newbie
 
Join Date: Jan 2009
Posts: 11
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

Last edited by Frinavale; May 25th, 2009 at 03:41 PM. Reason: Fixed code tags. Please poste code in [code] [/code] tags.
  #2  
Old June 29th, 2009, 02:30 PM
Newbie
 
Join Date: Jun 2009
Posts: 2

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

Last edited by insertAlias; June 29th, 2009 at 03:33 PM. Reason: Please use [CODE] tags when you post code.
  #3  
Old June 30th, 2009, 01:23 AM
Newbie
 
Join Date: Jan 2009
Posts: 11

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!
  #4  
Old June 30th, 2009, 02:00 PM
Newbie
 
Join Date: Jun 2009
Posts: 1

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.NET app compiled in Vista does not work on XP pmw answers 19 September 24th, 2008 04:15 PM
Can anyone tell me why this does not work? bill answers 9 July 23rd, 2008 06:45 AM
FileSystemWatcher Event Does Not Fire Lila Godel answers 1 June 27th, 2008 09:15 PM
self contained VB 2008 project that does not refer to the registry for transparent upgrades Steve House answers 0 June 27th, 2008 09:15 PM
VB 2008: Option Strict On + Infer On at class level Armin Zingler answers 15 December 13th, 2007 01:15 PM