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

Using Application.ShowModalDialog

7 REPLIES 7
Reply
Message 1 of 8
NikWach
3325 Views, 7 Replies

Using Application.ShowModalDialog

I created a new Windows Form in my DLL Extension and  try to make it open on a command:

 

public class DialogWindows
{
[CommandMethod("Form Dialog", CommandFlags.Modal)]
public void TestBrowserCommand()
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form1);
}
}

 

But the IDE show me an error (The name 'form1' does not exist in the current context.)

 

What is wrong?

7 REPLIES 7
Message 2 of 8
Matti72
in reply to: NikWach

You have to use a Instance of your Dialog... not the class...

 

I miss a line like

 

form1 dlg = new form1;

Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(dlg);

 

 

But if form1 is the Instance and not the className, than you are probably missing a using directive. Hard to say, without seeing the whole thing.

Message 3 of 8
NikWach
in reply to: Matti72

I just add to my project a new Windows Form, fill it with buttons, testboxes and so on.

 

Than I want this form to show in AutoCAD, when I use the command. There is nothing more to show(

Message 4 of 8
Matti72
in reply to: NikWach

The form1 you are using in thiis line:

Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form1);

 

has to be declared somewhere. 

 

Without showing your code, I have to guess, what it is and where it comes from...

 

The possibilities which I can think off are:

 

form1 is the Classname.

 

Than you have to use (as mentioned above)

form1 dlg = new form1();

and show the dlg.

 

Or:

 

form1 is the instance, than is the Question, where it is declared...

 

Possibility one would be static in the class (which would then normally be called Form1).

 

Then you have to use here Form1.form1;

 

Possibility two would be not static in the class Form1.

 

Then you need an Instanse of the class Form1, and use this

Also

Form1 f1 = new Form1()

And use then f1.Form1;

 

Or form1 is declared somewhere in your Command class... then the IDE should be happy.... 

 

You see, there is a lot someone might to see to help you. (The next question would be, if your command class and your Form are in the same dll and the same namespace....)

 

 

Message 5 of 8
NikWach
in reply to: NikWach

Here is the project

Message 6 of 8
Matti72
in reply to: NikWach

You have to use an instance... not a classname, as said before.

 

So you have to change:

[CommandMethod("Form Dialog")]
public void TestBrowserCommand()
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(MainApiDll_CSharp.Form1);
}

 

to

 

[CommandMethod("Form Dialog")]
public void TestBrowserCommand()
{
MainApiDll_CSharp.Form1 dlg = new MainApiDll_CSharp.Form1();
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(dlg);
}

 

Also you should consider to put your class DialogWindows in the same namespace then the rest of your project... this would than look so:

 

namespace MainApiDll_CSharp
{
	public class DialogWindows
	{
		[CommandMethod("Form Dialog")]
		public void TestBrowserCommand()
		{
			Form1 dlg = new Form1();
			Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(dlg);
		}
	}
}

 

Message 7 of 8
dgorsman
in reply to: Matti72

Also a good argument for descriptive and verbose naming (InterfaceTestForm vs. Form1).  Helps to keep things straight when working on larger projects, and when migrating code you haven't looked at for a couple of years.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 8 of 8
mzakiralam
in reply to: NikWach

Best way to show a form into AutoCAD using .NET API is like below:

 

Capture1.JPG

 

Application.MainWindow -- will make you form realize that it' parent is AutoCAD main editor

false -- will make sure that the form will not remember previous settings. As an example if you close your form in minimize mode or hide mode and when you call it again it will be minimized or hide and you will be in trouble somehow in that case..

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