One command-One form

One command-One form

Anonymous
Not applicable
523 Views
4 Replies
Message 1 of 5

One command-One form

Anonymous
Not applicable
Hi, all.
Whenever I return command, myform is generated.
It should not be generated, if the form already is.
Any good idea or tip?
Thank you in advance.

Dim Myform As DrawClothoid = New DrawClothoid
Application.ShowModalDialog(Myform)
0 Likes
524 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
use .net methods for show your form . you don`t need
Application.ShowModalDialog for showing the forms that created by .net .
in C# I follow this way for showing the form as dialog :

Form frm=new DrawClothoid();
frm.Showdialog();

or this for simple showing :

Form frm=new DrawClothoid();
frm.Show();

and consider that change to false the ShowInTaskbar peropertie of form. Message was edited by: afghari
0 Likes
Message 3 of 5

Anonymous
Not applicable
Firstly, you did not answer the OP's question. He want to load only one form
into Acad no matter how many times his command is executed.

Secondly, your advice is against Autodesk's recommendation. In the document,
it is clearly stated that a form/dialogbox should be shown by using

Application.ShowModalDialog()
Application.ShowModelessDialog()

Showing a form/dialog with .NET Form.Show()/ShowDialog() could lead to
unexpectced result, accroding to the doucment.

To the OP:

You can declare the Form as static member of the class, and only create the
form instance if it has not been created.

class Test
{
static MyForm frm=null;
[CommandMethod("TestCmd")]
public static void TestCommand()
{
//You only instantiate MyForm object when it hasn't been created
if (frm==null)
{
frm=new MyForm()
}

//Then show it here. You could set its Visible to True, or call
Application.ShowModal(Modeless)Dialog()...
}
}

"afghari" wrote in message news:[email protected]...
use .net methods for show your form . you don`t need
Application.ShowModalDialog for showing the forms that created by .net .
in C# I follow this way for showing the form as dialog :

Form frm=new DrawClothoid();
frm.Showdialog();

or this for simple showing :

Form frm=new DrawClothoid();
frm.Show();

and consider that change to false the ShowInTaskbar peropertie of form.

Message was edited by: afghari
0 Likes
Message 4 of 5

Anonymous
Not applicable
If you have a method in your form with the CommandMethod attribute, you must make the method Shared, because otherwise the managed runtime will create multiple instances of your form, one for each open document that you use the command in.

Best practice is to not add CommandMethod attributes to methods of UI components, and add them to a separate class instead.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:[email protected]...
Hi, all.
Whenever I return command, myform is generated.
It should not be generated, if the form already is.
Any good idea or tip?
Thank you in advance.

Dim Myform As DrawClothoid = New DrawClothoid
Application.ShowModalDialog(Myform)
0 Likes
Message 5 of 5

Anonymous
Not applicable
Thank you, thank you.
I did not know commandmethod should be separate command class.
0 Likes