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

Displaying WinForm with CommandMethod

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
1507 Views, 12 Replies

Displaying WinForm with CommandMethod

Hi Everyone,

I've been working with CommandMethod to create some AutoCAD commands that
interact with the user through prompts and messagebox display. Next, I want
to start using Winforms but I can't find any examples and the "trial and
error" approach has been failing me. I have the forms designed but can't
display them. I'm using AutoCAD 2006 and VS2005 Beta 2 on Windows XP SP2.

Any suggestions?

Thanks,

Scott
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

Hi Scott,
To display a form simply create an instance of it and call its .Show or
.ShowDialog method.
--
Bobby C. Jones
http://www.acadx.com


"Homer Simpson" wrote in message
news:4897447@discussion.autodesk.com...
Hi Everyone,

I've been working with CommandMethod to create some AutoCAD commands that
interact with the user through prompts and messagebox display. Next, I want
to start using Winforms but I can't find any examples and the "trial and
error" approach has been failing me. I have the forms designed but can't
display them. I'm using AutoCAD 2006 and VS2005 Beta 2 on Windows XP SP2.

Any suggestions?

Thanks,

Scott
Message 3 of 13
Anonymous
in reply to: Anonymous

I've been trying to do that but the intellisense won't display the
showdialog or show methods for the instance. The code is inserted below. I
also have one form named 'dataGatheringForm' in the project. Any suggestions
are greatly appreciated.

Thanks,
Scott


using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Windows;

namespace ProfileChecking

{

public class getData

{

[CommandMethod("CheckProfile")]

public void ShowForm();

{

Form dataForm = new dataGatheringForm();

// dataform. intellisense not working as expected...


}

}

}





"Bobby C. Jones" wrote in message
news:4897582@discussion.autodesk.com...
Hi Scott,
To display a form simply create an instance of it and call its .Show or
.ShowDialog method.
--
Bobby C. Jones
http://www.acadx.com


"Homer Simpson" wrote in message
news:4897447@discussion.autodesk.com...
Hi Everyone,

I've been working with CommandMethod to create some AutoCAD commands that
interact with the user through prompts and messagebox display. Next, I want
to start using Winforms but I can't find any examples and the "trial and
error" approach has been failing me. I have the forms designed but can't
display them. I'm using AutoCAD 2006 and VS2005 Beta 2 on Windows XP SP2.

Any suggestions?

Thanks,

Scott
Message 4 of 13
Anonymous
in reply to: Anonymous

Remove the semi-colon after this line.
>public void ShowForm();


Remember that C# is case sensitive. Your dataForm variable name is not the
same in these two lines.
>Form dataForm = new dataGatheringForm();
>// dataform. intellisense not working as expected...

--
Bobby C. Jones
http://www.acadx.com
Message 5 of 13
Anonymous
in reply to: Anonymous

Thanks, Bobby!

It was that @#*&% little semicolon!

I was focusing on checking the case of the variables and missed the line
terminator shouldn't be there. You have no idea how much time I already
spent trying to figure out what was wrong. I tried new projects, retyping
rather than cut & paste, etc.

Thanks,
Scott



"Bobby C. Jones" wrote in message
news:4897756@discussion.autodesk.com...
Remove the semi-colon after this line.
>public void ShowForm();


Remember that C# is case sensitive. Your dataForm variable name is not the
same in these two lines.
>Form dataForm = new dataGatheringForm();
>// dataform. intellisense not working as expected...

--
Bobby C. Jones
http://www.acadx.com
Message 6 of 13
Anonymous
in reply to: Anonymous

Glad to help out Scott. Sometimes that second pair of eyes makes all the
difference in the world!
--
Bobby C. Jones
http://www.acadx.com

"Homer Simpson" wrote in message
news:4897845@discussion.autodesk.com...
Thanks, Bobby!

It was that @#*&% little semicolon!

I was focusing on checking the case of the variables and missed the line
terminator shouldn't be there. You have no idea how much time I already
spent trying to figure out what was wrong. I tried new projects, retyping
rather than cut & paste, etc.

Thanks,
Scott
Message 7 of 13
Anonymous
in reply to: Anonymous

Here's a C# example.

Create a new solution with a c# project, add references to
System.Windows.Forms, and the AutoCAD managed DLLS,
then add a new Form to the project using the default name
"Form1".

Then, replace the entire Form1.cs file generated by the IDE
with the code below. Then, build the project and NETLOAD
into AutoCAD, and issue the MODALFORM command.

//////////// Form1.cs /////////////////
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace AcadModalFormSample
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

#region AutoCAD-specific functionality

private static Form1 s_ThisForm = null;

// singleton form object is created the
// first time this property is referenced.

private static Form1 ThisForm
{
get
{
if( s_ThisForm == null || s_ThisForm.IsDisposed )
s_ThisForm = new Form1();
return s_ThisForm;
}
}

[CommandMethod("MODALFORM")]
static public void FormShowCommandMethod()
{
AcadApp.ShowModalDialog(ThisForm);
}
#endregion
}
}

/////////////// end Form1.cs /////////////////
--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Homer Simpson" wrote in message news:4897447@discussion.autodesk.com...
Hi Everyone,

I've been working with CommandMethod to create some AutoCAD commands that
interact with the user through prompts and messagebox display. Next, I want
to start using Winforms but I can't find any examples and the "trial and
error" approach has been failing me. I have the forms designed but can't
display them. I'm using AutoCAD 2006 and VS2005 Beta 2 on Windows XP SP2.

Any suggestions?

Thanks,

Scott
Message 8 of 13
Anonymous
in reply to: Anonymous

"Bobby C. Jones" wrote:

>> To display a form simply create an instance of it and
>> call its .Show or .ShowDialog method.

In AutoCAD you do not call Show() or ShowDialog()

The interop Application class has methods for displaying
forms, and they should be used instead.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

--
Bobby C. Jones
http://www.acadx.com
Message 9 of 13
Anonymous
in reply to: Anonymous

Thanks Tony, Nice info.
"Tony Tanzillo" wrote in message
news:4898376@discussion.autodesk.com...
Here's a C# example.

Create a new solution with a c# project, add references to
System.Windows.Forms, and the AutoCAD managed DLLS,
then add a new Form to the project using the default name
"Form1".

Then, replace the entire Form1.cs file generated by the IDE
with the code below. Then, build the project and NETLOAD
into AutoCAD, and issue the MODALFORM command.

//////////// Form1.cs /////////////////
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace AcadModalFormSample
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion

#region AutoCAD-specific functionality

private static Form1 s_ThisForm = null;

// singleton form object is created the
// first time this property is referenced.

private static Form1 ThisForm
{
get
{
if( s_ThisForm == null || s_ThisForm.IsDisposed )
s_ThisForm = new Form1();
return s_ThisForm;
}
}

[CommandMethod("MODALFORM")]
static public void FormShowCommandMethod()
{
AcadApp.ShowModalDialog(ThisForm);
}
#endregion
}
}

/////////////// end Form1.cs /////////////////
--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Homer Simpson" wrote in message
news:4897447@discussion.autodesk.com...
Hi Everyone,

I've been working with CommandMethod to create some AutoCAD commands that
interact with the user through prompts and messagebox display. Next, I want
to start using Winforms but I can't find any examples and the "trial and
error" approach has been failing me. I have the forms designed but can't
display them. I'm using AutoCAD 2006 and VS2005 Beta 2 on Windows XP SP2.

Any suggestions?

Thanks,

Scott
Message 10 of 13
Anonymous
in reply to: Anonymous

I posted the example without seeing your code, and
a bit of explaination about the example may be helpful.

If a member function marked with the CommandMethod
attribute is not static, then AutoCAD is going to create
one instance of the containing class, for each drawing in
which the command is issued.

That means that if you have three drawings open in the
AutoCAD editor, and you issue the CheckProfile command
in each of them, then there will be three instances of your
getData class, one for each open document. Hence, there
will be three instances of your dataGatheringForm created
as well.

That scheme can be extremely useful in cases where the
form binds or couples to document-specific data. If the form
does not couple to document specific data, you may not
want to have multiple document-specific forms, and rather
have a single form that is used in all documents.

The choice of which way to go is largely dependent on the
nature of the form and the application it is a part of.

Just so that everyone knows, the sample I posted shows
how to display a single modal form that is used in every
open document, rather than use multiple document-specific
forms.

Lastly, Bobby's advice regarding showing the form, is not
correct for forms in managed applications loaded into the
AutoCAD process.

Instead of calling ShowDialog() or Show() to display your
form, in AutoCAD you would call the ShowModalDialog()
method of the Apolication object. For a modeless dialog,
there is the ShowModelessDialog() method. There are
several things that these methods do, which are desireable
in the case of AutoCAD-hosted winforms. So, you should
use those in lieu of the aforementioned Form methods.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Homer Simpson" wrote in message news:4897738@discussion.autodesk.com...
I've been trying to do that but the intellisense won't display the
showdialog or show methods for the instance. The code is inserted below. I
also have one form named 'dataGatheringForm' in the project. Any suggestions
are greatly appreciated.

Thanks,
Scott


using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Windows;

namespace ProfileChecking

{

public class getData

{

[CommandMethod("CheckProfile")]

public void ShowForm();

{

Form dataForm = new dataGatheringForm();

// dataform. intellisense not working as expected...


}

}

}





"Bobby C. Jones" wrote in message
news:4897582@discussion.autodesk.com...
Hi Scott,
To display a form simply create an instance of it and call its .Show or
.ShowDialog method.
--
Bobby C. Jones
http://www.acadx.com


"Homer Simpson" wrote in message
news:4897447@discussion.autodesk.com...
Hi Everyone,

I've been working with CommandMethod to create some AutoCAD commands that
interact with the user through prompts and messagebox display. Next, I want
to start using Winforms but I can't find any examples and the "trial and
error" approach has been failing me. I have the forms designed but can't
display them. I'm using AutoCAD 2006 and VS2005 Beta 2 on Windows XP SP2.

Any suggestions?

Thanks,

Scott
Message 11 of 13
Anonymous
in reply to: Anonymous

You are correct Tony. Thanks for pointing that out.
--
Bobby C. Jones
http://www.acadx.com

"Tony Tanzillo" wrote in message
news:4898361@discussion.autodesk.com...
"Bobby C. Jones" wrote:

>> To display a form simply create an instance of it and
>> call its .Show or .ShowDialog method.

In AutoCAD you do not call Show() or ShowDialog()

The interop Application class has methods for displaying
forms, and they should be used instead.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

--
Bobby C. Jones
http://www.acadx.com
Message 12 of 13
Mikko
in reply to: Anonymous

What are the advantages of using AutoCAD winforms?
Message 13 of 13
Anonymous
in reply to: Anonymous

If you build a managed assembly that's loaded with
NETLOAD, the point is moot. In that case, any Form
derivative is running in AutoCAD, so you can say they
are all 'AutoCAD winforms'.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4899861@discussion.autodesk.com...
What are the advantages of using AutoCAD winforms?

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