简体   繁体   中英

C# change windows form to ontop after opening an AutoCAD drawing

I have written a C# plugin for AutoCAD where the user can enter some information and afterwards the appropriate drawing should be openend.

The actual workflow should be:

  1. I start my plugin in AutoCAD
  2. The user can input some information in a windows form which is on top of the current active drawing
  3. When the user hits the enter button a new drawing should be opend
  4. The form where the user has entered some information should be closed (which works fine)
  5. A new window form should be opend to enter some other information (not the same window as the first one) BUT IN THE NEW DRAWING

The problem is that I can correctly close the first window and correclty open the new drawing. Like this:

    DocumentCollection documentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;

    if (File.Exists(absoultePathOfDrawing))
    {
    Document newDrawing = documentCollection.Open(absoultePathOfDrawing, false);
    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = newDrawing; // this sets the new drawing as the active one ==> is on top
    }

Dispose(); // closes the first form
DialogResult = DialogResult.OK; // tells my applciation that the first window was successfully closed

The form closes correctly and afterwards I try to open the new form with:

if (result == DialogResult.OK)
{
      MessageBox.Show("Test");          

}

But now the new drawing is on top and behind is the old drawing. When I switch back to the old drawing, the new MessageBox will be shown but actually this should be shown in the new drawing, because I set the active document to the new drawing. What am I doing wrong?

I have found the solution.

I had to load my plugin with the following option:

[CommandMethod("PluginName", Autodesk.AutoCAD.Runtime.CommandFlags.Session)]

Without this my plugin is only valid in one document (the one where I started my plugin)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM