新手入门必看:VectorDraw 常见问题整理大全(十)
VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。该库还支持许多矢量和栅格输入和输出格式,包括本地PDF和SVG导出。
【VectorDraw Developer Framework最新版下载】
VectorDraw web library (javascript)是一个矢量图形库。VectorDraw web library (javascript)不仅能打开CAD图纸,而且能显示任何支持HTML5标准平台上的通用矢量对象,如Windows,安卓,iOS和Linux。无需任何安装,VectorDraw web library (javascript)就可以运行在任何支持canvas标签和Javascript的主流浏览器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。
【VectorDraw web library (javascript)最新版下载】
一. 将数据对象从表示绘图的列表框拖放到VectorDraw Control作为插入对象
问:如何将数据对象从表示绘图的列表框拖放到VectorDraw Control作为插入对象?
答:参见以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using VectorDraw.Actions;
using VectorDraw.Geometry;
using VectorDraw.Professional.vdPrimaries;
using VectorDraw.Professional.vdCollections;
using VectorDraw.Professional.vdObjects;
using VectorDraw.Professional.ActionUtility;
using VectorDraw.Professional.vdFigures;
namespace WindowsApplication1
{
//Example of Drag & Drop a data object from a List box that represents a Drawing, in to VectorDraw Control as Insert object.
public partial class Form1 : Form
{
public vdInsert Winsert = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
vdDest.vdDragEnter += new VectorDraw.Professional.Control.DragEnterEventHandler(vdDest_vdDragEnter);
vdDest.vdDragDrop += new VectorDraw.Professional.Control.DragDropEventHandler(vdDest_vdDragDrop);
vdDest.vdDragOver +=new VectorDraw.Professional.Control.DragOverEventHandler(vdDest_vdDragOver);
vdDest.vdDragLeave += new VectorDraw.Professional.Control.DragLeaveEventHandler(vdDest_vdDragLeave);
vdDest.DrawOverAll += new VectorDraw.Professional.Control.DrawOverAllEventHandler(vdDest_DrawOverAll);
}
void vdDest_DrawOverAll(object sender, VectorDraw.Render.vdRender render, ref bool cancel)
{
if (Winsert == null) return;
//If this event is called when a DragDrop action is active (from vdDest_vdDragOver) then we repaint the screen with the Insret object in the curent Cursor position.
gPoint curpt = vdDest.ActiveDocument.CCS_CursorPos();
Winsert.InsertionPoint = curpt;
Winsert.Update();
render.UnLock();//use Unlock / Lock in order the rendering be smoother as GDIPlusRender
Winsert.Draw(render);
render.Lock();
}
void vdDest_vdDragLeave(EventArgs e, ref bool cancel)
{
//Leaving the VectorDraw control
cancel = true;
Winsert = null;
}
void vdDest_vdDragEnter(DragEventArgs drgevent, ref bool cancel)
{
//A drag drop action is active and the cursor is just activate in the VectorDraw screen
cancel = true;
//get the data object and check if is represents a drawing file.
DataObject dataobject = drgevent.Data as DataObject;
if (dataobject == null) return;
System.Collections.Specialized.StringCollection strings = dataobject.GetFileDropList();
if (strings == null || strings.Count != 1) return;
string filename = strings[0];
string blockname = System.IO.Path.GetFileNameWithoutExtension(filename);//get th block name of the file
vdBlock block = vdDest.ActiveDocument.Blocks.FindName(blockname);//if the block already exist in the drawing then we do not redifine it.
if (block == null)
{
Cursor curCursor = Cursor;
Cursor = Cursors.WaitCursor;
block = vdDest.ActiveDocument.Blocks.AddFromFile(filename, false);//add the block in the drawing
Cursor = curCursor;
}
if (block == null) return;
drgevent.Effect = DragDropEffects.Copy;
//create an insert object but we do not add it in the Document ActiveLayout entities.
Winsert = new vdInsert();
Winsert.SetUnRegisterDocument(vdDest.ActiveDocument);
Winsert.setDocumentDefaults();
Winsert.Block = block;
Winsert.CreateDefaultAttributes();
Winsert.InsertionPoint = vdDest.ActiveDocument.CCS_CursorPos();
Winsert.Update();
}
void vdDest_vdDragDrop(DragEventArgs drgevent, ref bool cancel)
{
cancel = true;
if (Winsert == null) return;
//Add the insert object in to Document ActiveLayout entities.
Winsert.Invalidate();
Winsert.InsertionPoint = vdDest.ActiveDocument.CCS_CursorPos();
Winsert.Update();
vdDest.ActiveDocument.ActiveLayOut.Entities.AddItem(Winsert);
Winsert.Invalidate();
Winsert = null;
}
private void vdDest_vdDragOver(DragEventArgs drgevent, ref bool cancel)
{
cancel = true;
if (Winsert == null) return;
gPoint curpt = vdDest.ActiveDocument.CCS_CursorPos();
//If the mouse is not moved then we do not refresh the graphics screen to avoid flicking
if (Winsert.InsertionPoint.AreEqual(curpt, vdDest.ActiveDocument.ActiveActionRender.PixelSize / 2.0d)) return;
//This command will refresh the graphics screen and call the vdDest_DrawOverAll event
vdDest.ActiveDocument.ActiveLayOut.RefreshGraphicsControl(null);
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
//Create a new data object that contains an existing file and begin a Drag drop operation.
DataObject data = new DataObject();
System.Collections.Specialized.StringCollection filepaths = new System.Collections.Specialized.StringCollection();
filepaths.Add(Application.StartupPath + "\\exemplo.dwg");
data.SetFileDropList(filepaths);
listBox1.DoDragDrop(data, DragDropEffects.Copy);
}
}
}
在版本7中,由于Render的更改,DrawOverAll不会像版本6那样不断触发。在这种情况下,代码应更改为:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using VectorDraw.Actions;
using VectorDraw.Generics;
using VectorDraw.Geometry;
using VectorDraw.Professional;
using VectorDraw.Professional.vdPrimaries;
using VectorDraw.Professional.vdCollections;
using VectorDraw.Professional.vdObjects;
using VectorDraw.Professional.ActionUtility;
using VectorDraw.Professional.vdFigures;
using VectorDraw.Render;
using VectorDraw.Serialize;
namespace Example_Drag_7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
vdInsert Winsert = null;
private void Form1_Load(object sender, EventArgs e)
{
vdDest.vdDragDrop += new VectorDraw.Professional.Control.DragDropEventHandler(vectorDrawBaseControl1_vdDragDrop);
vdDest.vdDragEnter += new VectorDraw.Professional.Control.DragEnterEventHandler(vectorDrawBaseControl1_vdDragEnter);
vdDest.vdDragLeave += new VectorDraw.Professional.Control.DragLeaveEventHandler(vectorDrawBaseControl1_vdDragLeave);
vdDest.vdDragOver += new VectorDraw.Professional.Control.DragOverEventHandler(vectorDrawBaseControl1_vdDragOver);
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
//Create a new data object that contains an existing file and begin a Drag drop operation.
DataObject data = new DataObject();
System.Collections.Specialized.StringCollection filepaths = new System.Collections.Specialized.StringCollection();
filepaths.Add(Application.StartupPath + "\\exemplo.dwg");
data.SetFileDropList(filepaths);
listBox1.DoDragDrop(data, DragDropEffects.Copy);
}
private void vectorDrawBaseControl1_vdDragDrop(DragEventArgs drgevent, ref bool cancel)
{
cancel = true;
if (Winsert == null) return;
//Add the insert object in to Document ActiveLayout entities.
vdDocument docAcess = vdDest.ActiveDocument;
Winsert.Invalidate();
Winsert.InsertionPoint = docAcess.CCS_CursorPos();
Winsert.Update();
docAcess.ActiveLayOut.Entities.AddItem(Winsert);
Winsert.Invalidate();
Winsert = null;
}
private void vectorDrawBaseControl1_vdDragEnter(DragEventArgs drgevent, ref bool cancel)
{
//A drag drop action is active and the cursor is just activate in the VectorDraw screen
cancel = true;
vdDocument docAccess = vdDest.ActiveDocument;
//get the data object and check if is represents a drawing file.
DataObject dataobject = drgevent.Data as DataObject;
if (dataobject == null) return;
System.Collections.Specialized.StringCollection strings = dataobject.GetFileDropList();
if (strings == null || strings.Count != 1) return;
string filename = strings[0];
string blockname = System.IO.Path.GetFileNameWithoutExtension(filename);//get th block name of the file
vdBlock block = docAccess.Blocks.FindName(blockname);//if the block already exist in the drawing then we do not redifine it.
if (block == null)
{
Cursor curCursor = Cursor;
Cursor = Cursors.WaitCursor;
block = docAccess.Blocks.AddFromFile(filename, false);//add the block in the drawing
Cursor = curCursor;
}
if (block == null) return;
drgevent.Effect = DragDropEffects.Copy;
//create an insert object but we do not add it in the Document ActiveLayout entities.
Winsert = new vdInsert();
Winsert.SetUnRegisterDocument(docAccess);
Winsert.setDocumentDefaults();
Winsert.Block = block;
Winsert.CreateDefaultAttributes();
Winsert.InsertionPoint = docAccess.CCS_CursorPos();
Winsert.Update();
}
private void vectorDrawBaseControl1_vdDragLeave(EventArgs e, ref bool cancel)
{ //Leaving the VectorDraw control
cancel = true;
Winsert = null;
vdDest.ActiveDocument.ActiveLayOut.Refresh();
}
private void vectorDrawBaseControl1_vdDragOver(DragEventArgs drgevent, ref bool cancel)
{
cancel = true;
if (Winsert == null) return;
vdDocument docAccess = vdDest.ActiveDocument;
gPoint curpt = docAccess.CCS_CursorPos();
curpt = docAccess.ActiveLayOut.User2WorldMatrix.Transform(curpt);
Winsert.InsertionPoint = curpt;
Winsert.Update();
vdRender render = docAccess.ActiveActionRender;
// Draw the insert in the mouse position
bool isstarted = render.Started;
if (!isstarted) render.StartDraw(true);
if (render.Started)
{
Winsert.Draw(render);
if (!isstarted) render.EndDraw();
}
}
}
}
二. 搜索Document以查找具有某个Block的插入
问:如何用一种方法来搜索整个Document以获得具有特定Block的插入?
答:可以尝试以下代码:
vdFramedControl.BaseControl.ActiveDocument.Prompt("Block name to search:");
string blockname = vdFramedControl.BaseControl.ActiveDocument.ActionUtility.getUserString();
vdFramedControl.BaseControl.ActiveDocument.Prompt(null);
if (blockname == null) return;
vdBlock blk = vdFramedControl.BaseControl.ActiveDocument.Blocks.FindName(blockname);
if (blk == null) return;
//search all vdPrimaries that are document register with handle != 0
vdSelection set = new vdSelection();//create a selection to hold the items
vdPrimariesList list = vdFramedControl.BaseControl.ActiveDocument.GetPrimaries(true);
foreach (vdPrimary var in list)
{
vdInsert test = var as vdInsert;
if (test == null) continue;
if (!object.ReferenceEquals(test.Block, blk)) continue;
set.AddItem(test, false, vdSelection.AddItemCheck.Nochecking);
}
三. 在打印机上打印多个页面
问:想在一个打印作业中打印图形的布局(每页一个布局)。该怎么做?
答:这适用于版本6011及之后。可以尝试以下代码:
public void Print_Clicked()
{
//because UpdatePropertiesFromPrinter was changed and you can not change the System.Drawing.Printing.PrintDocument object of a vdPrinter
//the following logic must be used.
//Create a New printer object and set it as DocumentUnregister
vdPrint printer = new vdPrint();//new change
printer.SetUnRegisterDocument(vdPro.ActiveDocument);//new change
//Get the System.Drawing.Printing.PrintDocument from previous created vdPrinter object.
//System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();//new change
System.Drawing.Printing.PrintDocument printDoc = printer.UpdatePrinterFromProperties();//new change
System.Drawing.Printing.PrintEventArgs printArgs = new System.Drawing.Printing.PrintEventArgs();
printDoc.DocumentName = "TestPrint.pdf";
printDoc.PrinterSettings.PrinterName = "CutePDF Writer";//@\\myServer\HP Deskjet 9800 Series; // "Adobe PDF"; // Enter Custom PrinterName here..
//Update the printer properties
printer.UpdatePropertiesFromPrinter(printDoc);//new change
//Start multipage printing
printDoc.PrintController.OnStartPrint(printDoc, printArgs);
// Actually print each page to the printer
foreach (vdLayout layout in vdPro.ActiveDocument.LayOuts)
{
printer.SetLayout(layout);//new change
printer.CenterDrawingToPaper();//new change
printer.PrintOutPage();//new change
//layout.Printer.UpdatePropertiesFromPrinter(printDoc);
//layout.Printer.CenterDrawingToPaper();
//layout.Printer.PrintOutPage();
}
// now print them Phsyically
printDoc.PrintController.OnEndPrint(printDoc, printArgs);
}
请尝试上面的代码,并检查此代码中的备注。
四. 在将vdtext的高度和宽度添加到文档之前获取它的高度和宽度
问:如何在将vdtext的高度和宽度添加到文档之前获取它,就像版本的5 GetTextSize函数一样?
答:可以试试以下代码:
Private Function GetTextSize(ByVal TextString As String, ByVal tstyle As VectorDraw.Professional.vdPrimaries.vdTextstyle, ByVal Height As Double, ByRef duHeight As Double, ByRef duWidth As Double) As Boolean duWidth = 0 : duHeight = 0 'Add a check like : If tstyle is nothing/null or textstring is empty exit sub If tstyle Is Nothing Then Return False If TextString Is Nothing Or TextString = "" Then Return False Dim text As VectorDraw.Professional.vdFigures.vdText = New VectorDraw.Professional.vdFigures.vdText() text.SetUnRegisterDocument(VectorDrawBaseControl1.ActiveDocument) text.setDocumentDefaults() text.Style = tstyle text.TextString = TextString text.Height = Height text.Update() duWidth = text.BoundingBox.Width duHeight = text.BoundingBox.Height Return True End Function
未完待续......

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线