• <menu id="w2i4a"></menu>
  • logo VectorDraw教程
    文檔首頁>>VectorDraw教程>>新手入門必看:VectorDraw 常見問題整理大全(十)

    新手入門必看:VectorDraw 常見問題整理大全(十)


    VectorDraw Developer Framework(VDF)是一個用于應(yīng)用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。該庫還支持許多矢量和柵格輸入和輸出格式,包括本地PDF和SVG導(dǎo)出。

    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)最新版下載

    一. 將數(shù)據(jù)對象從表示繪圖的列表框拖放到VectorDraw Control作為插入對象

    問:如何將數(shù)據(jù)對象從表示繪圖的列表框拖放到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那樣不斷觸發(fā)。在這種情況下,代碼應(yīng)更改為:

    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);
    }

    三. 在打印機上打印多個頁面

    問:想在一個打印作業(yè)中打印圖形的布局(每頁一個布局)。該怎么做?

    答:這適用于版本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函數(shù)一樣?

    答:可以試試以下代碼:

    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

    未完待續(xù)......

    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();