Personally, it is convenient to use the command to operate CAD, but given how many people prefer to operate CAD by mouse click, here's how to call WinForm. Pre-Preparation please see article.
1. Create a new WinForm or user control under the premise of creating a new project and referencing the interface DLL.
Calling WinForm directly generates a CAD-independent form on your computer and I feel uncomfortable, so I'll go directly to the process of generating paletteset (embedded in the CAD window).
2, the call process is actually executing a function, and the call of the function requires the user Input command (of course, you can also let the call automatically), after designing the user control, we write the following code in any of the classes:
Publicclassmain:iextensionapplication {[Commandmethod ("Show")] PublicvoidInitialize () {UserControl1 control1=NewUserControl1 (); Paletteset PS=NewPaletteset ("Panel 1"); Ps. Size=NewSystem.Drawing.Size ( -, -); Ps. Style=Palettesetstyles.showclosebutton; Ps. ADD ("User Controls", Control1); Ps. Visible=true; } PublicvoidTerminate () {}}
3, and the execution of a common command, in the CAD Command window, enter show will be on the left side of the CAD window to generate a panel embedded in the CAD, the above buttons can be used normally.
Attach a button event:
PrivatevoidMi1_click (Objectsender, EventArgs e) {Document doc=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Doc. Sendstringtoexecute (" Line",true,false,true);//There is a space behind line to determine}
The above code is exactly the same as the command line input, which calls the CAD internal name.
C # operations cad-call WinForm