WaitCursor at the command line

WaitCursor at the command line

hericson
Advocate Advocate
3,849 Views
14 Replies
Message 1 of 15

WaitCursor at the command line

hericson
Advocate
Advocate
To display the wait cursor when using a form I use System.Windows.Forms Namespace like this (VB.NET):

System.Windows.Forms.Cursor = Cursors.WaitCursor

But how should I do if I don't use a form? I ask for some options from the command line and while executing my code I want to display a wait cursor (still VB.NET).
0 Likes
3,850 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
hericson wrote:

> But how should I do if I don't use a form?

Have you considered using a ProgressMeter instead? If you know the
number of iterations it seems like a better option.

Terry
0 Likes
Message 3 of 15

hericson
Advocate
Advocate
Yes, I have considered that. But I have some problems with the progress meter, testing using a simple for next loop from 1 to 100 it will count all the percents but when using in it my real case it will only show every 6 percents and I can't figure out why.
Secondly I think it should be one way to show an hourglass without a form.
0 Likes
Message 4 of 15

Anonymous
Not applicable
Are there only 16 or 17 loops in your real world example?
0 Likes
Message 5 of 15

hericson
Advocate
Advocate
I had over 5000 loops but I found out that the order of pm.Start and pm.SetLimit made a difference (pm.Start first) and I also had to add pm.Dispose after pm.Stop to get it to work so that's not a problem anymore.
0 Likes
Message 6 of 15

Anonymous
Not applicable
You can reference System.Windows.Forms from any app,
even if it doesn't use any forms or UI components.

If for some reason you need to avoid referencing WinForms,
the only other option is P/Invoking the SetCursor() API

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:[email protected]...
To display the wait cursor when using a form I use System.Windows.Forms
Namespace like this (VB.NET):

System.Windows.Forms.Cursor = Cursors.WaitCursor

But how should I do if I don't use a form? I ask for some options from the
command line and while executing my code I want to display a wait cursor
(still VB.NET).
0 Likes
Message 7 of 15

Anonymous
Not applicable
Tony Tanzillo wrote:
> You can reference System.Windows.Forms from any app,
> even if it doesn't use any forms or UI components.
>
> If for some reason you need to avoid referencing WinForms,
> the only other option is P/Invoking the SetCursor() API
>

Can you give an example with the correct namespace because when I try
with: System.Windows.Forms.Cursor = Cursors.WaitCursor I'll get an error
message: 'Cursor' is an type in 'Forms' and cannot be use as an expression.

If I have a form I just have this code: Me.Cursor = Cursors.WaitCursor
0 Likes
Message 8 of 15

Anonymous
Not applicable
Here's what I use:

{code}

using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;

namespace MyNamespace
{
public class CurrentCursor : IDisposable
{
private Cursor saved = Cursor.Current;

public CurrentCursor( Cursor newCursor )
{
Cursor.Current = newCursor;
}

public void Dispose()
{
Cursor.Current = this.saved;
}
}

public class WaitCursor : CurrentCursor
{
public WaitCursor()
: base( Cursors.WaitCursor )
{
}
}

// example usage:

public class MyCommands
{
[CommandMethod("MYCOMMAND")
public static void MyCommand()
{
using( new WaitCursor() )
{
// wait cursor is visible here,
// so do what you need to do

} // the prevous cursor is restored here.
}
}

}

{code}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"Hericson" wrote in message
news:[email protected]...
Tony Tanzillo wrote:
> You can reference System.Windows.Forms from any app,
> even if it doesn't use any forms or UI components.
>
> If for some reason you need to avoid referencing WinForms,
> the only other option is P/Invoking the SetCursor() API
>

Can you give an example with the correct namespace because when I try
with: System.Windows.Forms.Cursor = Cursors.WaitCursor I'll get an error
message: 'Cursor' is an type in 'Forms' and cannot be use as an expression.

If I have a form I just have this code: Me.Cursor = Cursors.WaitCursor
0 Likes
Message 9 of 15

hericson
Advocate
Advocate
Sorry but I'm not able to convert your sample to VB.NET (lack of skills I guess). I think I can understand the example but not how to make the two classes into VB.NET.
0 Likes
Message 10 of 15

Anonymous
Not applicable
Imports System.Windows.Forms
Imports Autodesk.AutoCAD.Runtime

Namespace MyNamespace
    Public Class CurrentCursor
        Implements IDisposable
        Private saved As Cursor = Cursor.Current
       
        Public Sub New(ByVal newCursor As Cursor)
            Cursor.Current = newCursor
        End Sub
       
        Public Sub Dispose()
            Cursor.Current = Me.saved
        End Sub
    End Class
   
    Public Class WaitCursor
        Inherits CurrentCursor
        Public Sub New()
            MyBase.New(Cursors.WaitCursor)
        End Sub
    End Class
   
    ' example usage:
   
    Public Class MyCommands
        _
        Public Shared Sub MyCommand()
            Using New WaitCursor()
                ' wait cursor is visible here,
                ' so do what you need to do
               
                ' the prevous cursor is restored here.
            End Using
        End Sub
    End Class
   
End Namespace
Message 11 of 15

Anonymous
Not applicable
For future reference, there are a number of ways to translate C# code to
VB.NET code.

You can use reflector (http://www.red-gate.com/products/reflector/), or any
number of online translators (google 'translate C# to VB').

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:[email protected]...
Sorry but I'm not able to convert your sample to VB.NET (lack of skills I
guess). I think I can understand the example but not how to make the two
classes into VB.NET.
0 Likes
Message 12 of 15

hericson
Advocate
Advocate
Thanks for the link.

I have a problem in the code above and that is the Implements IDisposable row. It will give me an error I don't understand:

Class 'CurrentCursor' must implement 'Sub Dispose()' for interface 'System.IDisposable'.
0 Likes
Message 13 of 15

Anonymous
Not applicable
Change the Dispose() method to:


Public Sub Dispose() Implements IDisposable.Dispose
Cursor.Current = Me.saved
End Sub


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:[email protected]...
Thanks for the link.

I have a problem in the code above and that is the Implements IDisposable
row. It will give me an error I don't understand:

Class 'CurrentCursor' must implement 'Sub Dispose()' for interface
'System.IDisposable'.
0 Likes
Message 14 of 15

Anonymous
Not applicable
{code}
wrote in message news:[email protected]...
Thanks for the link.

I have a problem in the code above and that is the Implements IDisposable
row. It will give me an error I don't understand:

Class 'CurrentCursor' must implement 'Sub Dispose()' for interface
'System.IDisposable'.
0 Likes
Message 15 of 15

Anonymous
Not applicable
I hit some send button on the keyboard oops... Tony answered anyway.
"Paul Richardson" wrote in message
news:[email protected]...
{code}
wrote in message news:[email protected]...
Thanks for the link.

I have a problem in the code above and that is the Implements IDisposable
row. It will give me an error I don't understand:

Class 'CurrentCursor' must implement 'Sub Dispose()' for interface
'System.IDisposable'.
0 Likes