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.
DialogResult result = insertFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string blockQualifiedFileName = insertFileDialog1.Filename;
string blockName = Path.GetFileNameWithoutExtension(blockQualifiedFileName);
InsertDrawing(blockQualifiedFileName, blockName, doc, db);
LundFileDialog.ActiveForm.Close();
}
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:
private static void InsertDrawing(string blockQualifiedFileName, string blockName, Document doc, Database db)
{
try
{
Editor ed = doc.Editor;
using (doc.LockDocument())
{
using (Transaction transaction = doc.TransactionManager.StartTransaction())
{
Database tmpDb
= new Database
(false,
true); tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.ReadWrite, true, null);
ed.WriteMessage("\n blockname: " + blockName + " - " + blockQualifiedFileName);
db.Insert(blockName, tmpDb, true);
BlockTable table = (BlockTable)transaction.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord record = (BlockTableRecord)transaction.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
if (table.Has(blockName))
{
PromptPointResult ppr = ed.GetPoint("\nSpecify insertion point: ");
if (ppr.Status != PromptStatus.OK)
return;
BlockReference reference
= new BlockReference
(ppr
.Value, table
[blockName
]);
record.AppendEntity(reference);
transaction.AddNewlyCreatedDBObject(reference, true);
reference.RecordGraphicsModified(true);
}
else
{
ed.WriteMessage("Block name not found:");
}
tmpDb.Dispose();
transaction.Commit();
}
}
}
catch (SystemException exception)
{
MessageBox.Show("Insert Failed :" + exception.InnerException);
}
}