.NET

Reply
Valued Contributor
hericson
Posts: 69
Registered: ‎12-03-2006
Message 1 of 15 (493 Views)

WaitCursor at the command line

493 Views, 14 Replies
08-11-2009 02:14 AM
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).
*Terry W. Dotson
Message 2 of 15 (492 Views)

Re: WaitCursor at the command line

08-11-2009 07:10 AM in reply to: hericson
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
Valued Contributor
hericson
Posts: 69
Registered: ‎12-03-2006
Message 3 of 15 (492 Views)

Re: WaitCursor at the command line

08-13-2009 01:43 AM in reply to: hericson
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.
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 4 of 15 (492 Views)

Re: WaitCursor at the command line

08-13-2009 05:29 AM in reply to: hericson
Are there only 16 or 17 loops in your real world example?
Valued Contributor
hericson
Posts: 69
Registered: ‎12-03-2006
Message 5 of 15 (492 Views)

Re: WaitCursor at the command line

08-13-2009 05:59 AM in reply to: hericson
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.
*Tony Tanzillo
Message 6 of 15 (492 Views)

Re: WaitCursor at the command line

08-13-2009 03:56 PM in reply to: hericson
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:6234752@discussion.autodesk.com...
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).
*Hericson
Message 7 of 15 (492 Views)

Re: WaitCursor at the command line

08-14-2009 06:19 AM in reply to: hericson
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
*Tony Tanzillo
Message 8 of 15 (492 Views)

Re: WaitCursor at the command line

08-14-2009 07:48 AM in reply to: hericson
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:6237315@discussion.autodesk.com...
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
Valued Contributor
hericson
Posts: 69
Registered: ‎12-03-2006
Message 9 of 15 (492 Views)

Re: WaitCursor at the command line

08-15-2009 05:30 AM in reply to: hericson
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.
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 10 of 15 (492 Views)

Re: WaitCursor at the command line

08-15-2009 06:38 PM in reply to: hericson
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
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.