.NET

Reply
*Homer Simpson
Message 1 of 13 (323 Views)

Displaying WinForm with CommandMethod

323 Views, 12 Replies
07-10-2005 09:23 PM
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
*Bobby C. Jones
Message 2 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 05:14 AM in reply to: *Homer Simpson
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
*Homer Simpson
Message 3 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 07:18 AM in reply to: *Homer Simpson
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
*Bobby C. Jones
Message 4 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 07:31 AM in reply to: *Homer Simpson
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
*Homer Simpson
Message 5 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 08:22 AM in reply to: *Homer Simpson
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
*Bobby C. Jones
Message 6 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 08:25 AM in reply to: *Homer Simpson
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
*Tony Tanzillo
Message 7 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 02:26 PM in reply to: *Homer Simpson
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
*Tony Tanzillo
Message 8 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 02:29 PM in reply to: *Homer Simpson
"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
*Paul Richardson
Message 9 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 02:34 PM in reply to: *Homer Simpson
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
*Tony Tanzillo
Message 10 of 13 (323 Views)

Re: Displaying WinForm with CommandMethod

07-11-2005 03:50 PM in reply to: *Homer Simpson
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
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

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