Author Topic: Form Close makes flash on screen  (Read 2137 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Form Close makes flash on screen
« on: September 02, 2014, 03:24:51 PM »
Acad 2012, VS2010 exp.

I'm using a form that allows the user to click a button that uses an openfile dialog to select a file to insert into the current drawing.

Code - C#: [Select]
  1. DialogResult result = insertFileDialog1.ShowDialog();
  2.  
  3.                 if (result == DialogResult.OK)
  4.                 {
  5.                     string blockQualifiedFileName = insertFileDialog1.Filename;
  6.                     string blockName = Path.GetFileNameWithoutExtension(blockQualifiedFileName);
  7.  
  8.                     InsertDrawing(blockQualifiedFileName, blockName, doc, db);
  9.  
  10.                     LundFileDialog.ActiveForm.Close();
  11.                 }
  12.  

When a file is selected, a call to the  "InsertDrawing" method is performed that contains a call to promptPointResult which hides the main form.
After the point is picked and the drawing selected is brought into the current drawing as a block, I want to close the main form.
When I do using form.Close(); there is a momentary "flash" of the main form on the screen that happens almost simutaineously with the block being inserted.
The flash is about the same size and has features similar to the main form so I'm assuming it is the main form doing this.
Maybe I'm doing more than I'd have to, to insert a drawing as a block?

This is the method I'm using to insert the drawing seleted as a block:
Code - C#: [Select]
  1. private static void InsertDrawing(string blockQualifiedFileName, string blockName, Document doc, Database db)
  2.         {
  3.             try
  4.             {
  5.                 Editor ed = doc.Editor;
  6.                 using (doc.LockDocument())
  7.                 {
  8.                     using (Transaction transaction = doc.TransactionManager.StartTransaction())
  9.                     {
  10.                         Database tmpDb = new Database(false, true);
  11.                         tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.ReadWrite, true, null);
  12.                         ed.WriteMessage("\n blockname: " + blockName + " - " + blockQualifiedFileName);
  13.                         db.Insert(blockName, tmpDb, true);
  14.  
  15.                         BlockTable table = (BlockTable)transaction.GetObject(db.BlockTableId, OpenMode.ForWrite);
  16.                         BlockTableRecord record = (BlockTableRecord)transaction.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  17.  
  18.                         if (table.Has(blockName))
  19.                         {
  20.                             PromptPointResult ppr = ed.GetPoint("\nSpecify insertion point: ");
  21.                             if (ppr.Status != PromptStatus.OK)
  22.                                 return;                            
  23.  
  24.                             BlockReference reference = new BlockReference(ppr.Value, table[blockName]);
  25.  
  26.                             record.AppendEntity(reference);
  27.                             transaction.AddNewlyCreatedDBObject(reference, true);
  28.                             reference.RecordGraphicsModified(true);
  29.                         }
  30.                         else
  31.                         {
  32.                             ed.WriteMessage("Block name not found:");
  33.                         }
  34.  
  35.                         tmpDb.Dispose();
  36.                         transaction.Commit();
  37.                     }
  38.                 }
  39.             }
  40.             catch (SystemException exception)
  41.             {
  42.                 MessageBox.Show("Insert Failed :" + exception.InnerException);
  43.             }
  44.         }
  45.  
  46.  

BillZndl

  • Guest
Re: Form Close makes flash on screen
« Reply #1 on: September 03, 2014, 08:25:30 AM »
Seemed to have solved the problem. Guess I didn't mention what type of form I was using.
I ended up using a modeless form instead of a modal form.
I was having problems opening Autocad drawings in SDI = 0 from the modal form and ran accross some info from our old friend TT.
See: http://forums.autodesk.com/t5/net/invalid-execution-context/td-p/2595762

Then I overrode the closing event for the form instance:
protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            e.Cancel = true;
            Visible = false;
        }
No more screen flash problems.  :)

I've been coverting old autolisp code to net for some things we use a lot here at the plant.


MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Form Close makes flash on screen
« Reply #2 on: September 03, 2014, 04:01:54 PM »
I can't resist,  not having this issue in WPF.
Revit 2019, AMEP 2019 64bit Win 10

BillZndl

  • Guest
Re: Form Close makes flash on screen
« Reply #3 on: September 04, 2014, 10:38:17 AM »
I can't resist,  not having this issue in WPF.

Oh, that one is nothing compared to feeding the Acad openfiledialog the correct filename and have it occasionally refuse to open in that directory. :roll:

BillZndl

  • Guest
Re: Form Close makes flash on screen
« Reply #4 on: September 09, 2014, 12:55:49 PM »
I can't resist,  not having this issue in WPF.

Just a quick followup.
I did some poking around, looking into WPF dialog boxes.
Can these be used with programs that are net loaded autocad .dll's?
I'd like to find out what I'm up against before I spend too much time getting no where.

TIA

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: Form Close makes flash on screen
« Reply #5 on: September 09, 2014, 01:04:50 PM »
From AutoCAD 2013 you can use WPF. No problem. AutoCAD uses a lot of WPF too.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

BillZndl

  • Guest
Re: Form Close makes flash on screen
« Reply #6 on: September 09, 2014, 03:15:47 PM »
k, thanks!
We're still on 2012 but I know they have 2015 laying around here somewhere.
Management don't like to get more than about 2 versions behind on anything so I'm thinking we will be making the jump soon.
At least we have CUI's now and I have most of our user interface stuff converted over to net.
Last time I had to debug autolisp I can remember thinking, "how did I ever do this without intellisense?" and "so many parens!!!" :lol: .
I wasn't looking forward to going through another version upgrade without upgrading some code first.