.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

WaitCursor at the command line

14 REPLIES 14
Reply
Message 1 of 15
hericson
1521 Views, 14 Replies

WaitCursor at the command line

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).
14 REPLIES 14
Message 2 of 15
Anonymous
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
Message 3 of 15
hericson
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.
Message 4 of 15
NathTay
in reply to: hericson

Are there only 16 or 17 loops in your real world example?
Message 5 of 15
hericson
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.
Message 6 of 15
Anonymous
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).
Message 7 of 15
Anonymous
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
Message 8 of 15
Anonymous
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
Message 9 of 15
hericson
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.
Message 10 of 15
NathTay
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
Message 11 of 15
Anonymous
in reply to: hericson

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:6237829@discussion.autodesk.com...
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.
Message 12 of 15
hericson
in reply to: hericson

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'.
Message 13 of 15
Anonymous
in reply to: hericson

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:6238441@discussion.autodesk.com...
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'.
Message 14 of 15
Anonymous
in reply to: hericson

{code}
wrote in message news:6238441@discussion.autodesk.com...
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'.
Message 15 of 15
Anonymous
in reply to: hericson

I hit some send button on the keyboard oops... Tony answered anyway.
"Paul Richardson" wrote in message
news:6238509@discussion.autodesk.com...
{code}
wrote in message news:6238441@discussion.autodesk.com...
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'.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost