Article | 60000414 |
Type | HowTo |
Product | Engine |
Version | 6 |
Date Added | 2/6/2008 |
Submitted by | Pablo Linares |
Keywords |
andobject ByteArray = null;
System.IO.MemoryStream memorystream = Doc.ToStream(); //doc can be the BaseControl.ActiveDocument or vdDoc1.Document or vdFrame.BaseControl.ActiveDocument
if (memorystream == null) return 0;
ByteArray = memorystream.ToArray();
int size = (int)memorystream.Length;
memorystream.Close();
// then SAVE the ByteArray to your database
// Read the Bytes from database and store it in the ByteArray and then :
System.IO.MemoryStream memorystream = new System.IO.MemoryStream((byte[])ByteArray);
memorystream.Position = 0;
Doc.LoadFromMemory(memorystream);
memorystream.Close();
The sample has no DATABASE code inside and for this a vdScrollable control ( vdSC_from control) is used to create and save the document in a ByteArray so it will be used to simulate the fill of the ByteArray from a database record/field. Then this ByteArray is "transformed" back in a Document using a temporary vdDocument control (vdDocComp_Temp), and then the AddFromDocument method of vdBlocks object is used to produce the vdBlock object that is inserted in the drawing (as vdInsert) of the vdFramed Control. See also the remarks bellow.
The code should be :
public partial class Form1 : Form
// now we will read this to the temporary document
VectorDraw.Professional.vdObjects.vdDocument
DocumentToBlock = vdDocComp_Temp.Document;
DocumentToBlock.New();
memorystream =
new System.IO.MemoryStream((byte[])ByteArray);
memorystream.Position = 0;
DocumentToBlock.LoadFromMemory(memorystream,
true);//Read
from memory compressed
memorystream.Close();
//and add the entities of this document to a block
//We create a block object and
initialize it's default properties.
VectorDraw.Professional.vdCollections.vdBlocks
blks =
vdFC_To.BaseControl.ActiveDocument.Blocks;
VectorDraw.Professional.vdPrimaries.vdBlock
blk = blks.AddFromDocument("CustomBlock1",DocumentToBlock,true);
blk.Update();
//add the block to the blocks
collection
vdFC_To.BaseControl.ActiveDocument.Blocks.AddItem(blk);
//and now insert it;
vdFC_To.BaseControl.ActiveDocument.CommandAction.CmdInsert("CustomBlock1",
new
VectorDraw.Geometry.gPoint(0.0d,
3.0d, 0.0d), 1d, 2d, 2d);
}
private
void
button2_Click(object
sender, EventArgs
e)
{
//instead of a database, a VectorDraw Scrollable control (vdSC_From)
is used to create a drawing to a bytearray
vdSC_From.BaseControl.ActiveDocument.New();
vdSC_From.BaseControl.ActiveDocument.CommandAction.CmdRect(new
VectorDraw.Geometry.gPoint(2.0d,
1d, 0d), new
VectorDraw.Geometry.gPoint(3.0d,
4d, 0d));
vdSC_From.BaseControl.ActiveDocument.ActivePenColor.ColorIndex = 3;
vdSC_From.BaseControl.ActiveDocument.CommandAction.CmdArc(new
VectorDraw.Geometry.gPoint(4.0d,
0d, 0d),2d, 1.0d,2.0d);
object
ByteArray = null;
System.IO.MemoryStream
memorystream = vdSC_From.BaseControl.ActiveDocument.ToStream(true);
if (memorystream
== null)
return;
ByteArray = memorystream.ToArray();
int size = (int)memorystream.Length;
memorystream.Close();
// the drawing/document is created
and saved to a public ByteArray
// now we will read this to the temporary document
VectorDraw.Professional.vdObjects.vdDocument
DocumentToBlock = vdDocComp_Temp.Document;
DocumentToBlock.New();
memorystream =
new System.IO.MemoryStream((byte[])ByteArray);
memorystream.Position = 0;
DocumentToBlock.LoadFromMemory(memorystream,true);
memorystream.Close();
//and add the entities of this document to a block
//We create a block object and
initialize it's default properties.
VectorDraw.Professional.vdCollections.vdBlocks
blks =
vdFC_To.BaseControl.ActiveDocument.Blocks;
VectorDraw.Professional.vdPrimaries.vdBlock
blk = blks.AddFromDocument("CustomBlock2",
DocumentToBlock, true);
blk.Update();
//add the block to the blocks
collection
vdFC_To.BaseControl.ActiveDocument.Blocks.AddItem(blk);
//and now insert it;
vdFC_To.BaseControl.ActiveDocument.CommandAction.CmdInsert("CustomBlock2",
new
VectorDraw.Geometry.gPoint(0.0d,
3.0d, 0.0d), 1d, 2d, 2d);
}
}