新手入門必看: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標(biāo)準(zhǔn)平臺上的通用矢量對象,如Windows,安卓,iOS和Linux。無需任何安裝,VectorDraw web library (javascript)就可以運行在任何支持canvas標(biāo)簽和Javascript的主流瀏覽器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。
【VectorDraw web library (javascript)最新版下載】
一. 更改鼠標(biāo)光標(biāo)或?qū)⑵潆[藏
問:如何更改鼠標(biāo)光標(biāo)或隱藏它?
答:你可以使用SetCustomMousePointer方法將光標(biāo)更改為Cursor(在下面的代碼中更改為Cursors.PanNW)。要隱藏光標(biāo),你需要使用屬性ShowCursor和vdMouseEnter事件。請看以下代碼:
private void Form1_Load(object sender, EventArgs e) { vdFramedControl1.BaseControl.vdMouseEnter += new VectorDraw.Professional.Control.MouseEnterEventHandler(BaseControl_vdMouseEnter); } private bool show_pointer = true; // a flag in the form that controls if the cursor will be visible or not. void BaseControl_vdMouseEnter(EventArgs e, ref bool cancel) { if (show_pointer) return; // show the cursor //else hide the cursor with the code below cancel = true; vdFramedControl1.BaseControl.ActiveDocument.GlobalRenderProperties.ShowCursor = false; //Hide cursor vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.MouseEnter(this, e); // this is needed } private void button7_Click(object sender, EventArgs e) // Button to set the cursor to another cursor { vdFramedControl1.BaseControl.SetCustomMousePointer(Cursors.PanNW); // set the cursor to another cursor //using GetCustomeMousePointer you can get the cursor. } private void button8_Click(object sender, EventArgs e) //Button to set the cursor to default VDF cross { vdFramedControl1.BaseControl.SetCustomMousePointer(null); // set the cursor to VDF cross } private void button9_Click(object sender, EventArgs e)//Button to Hide the cursor { show_pointer = false; vdFramedControl1.BaseControl.ActiveDocument.GlobalRenderProperties.ShowCursor=false; //Hide cursor } private void button10_Click(object sender, EventArgs e) //Button to show the cursor { show_pointer = true; vdFramedControl1.BaseControl.ActiveDocument.GlobalRenderProperties.ShowCursor=true; //Show cursor } Another way to hide the cursor, is to change it to an "empty"/"transparent" cursor that you will add to your project resources. In this case you will not need the vdMouseEnter event and the global flag and your code should be : private void button9_Click(object sender, EventArgs e) { vdFramedControl1.BaseControl.SetCustomMousePointer(new Cursor(WindowsApplication1.Properties.Resources.Icon1.Handle)); // set the cursor to an "empty/transparent" cursor Icon1. } private void button10_Click(object sender, EventArgs e) { vdFramedControl1.BaseControl.SetCustomMousePointer(null); // set it to the default (visible) }
二. 在所有圖紙上繪制圖紙的示例
問:我想實現(xiàn)一些功能,在屏幕上的所有實體的頂部呈現(xiàn)覆蓋。在開始時,我只想在當(dāng)前的vdraw視圖的左下角繪制一個日期字符串。該文本將是視圖獨立的,因此無論用戶選擇何種3D視圖,都將面向用戶繪制。我也希望文本周圍有點陰影,以便很容易看到。你認為最佳方法是什么?能否給出代碼示例呢,謝謝!
答:可使用vdFramed控件的C#Windows應(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.Professional.vdObjects; using VectorDraw.Professional.vdFigures; using VectorDraw.Professional.vdPrimaries; using VectorDraw.Generics; using VectorDraw.Geometry; using VectorDraw.Professional.vdCollections; using VectorDraw.Actions; namespace WindowsApplication2 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private vdDocument doc { get { return vdFramedControl1.BaseControl.ActiveDocument; } } VectorDraw.Render.grTextStyle textstyle = null; protected override void OnLoad(EventArgs e) { base.OnLoad(e); doc.OnDrawAfter += new vdDocument.DrawAfterEventHandler(doc_OnDrawAfter); doc.OnDrawOverAll += new vdDocument.DrawOverAllEventHandler(doc_OnDrawOverAll); //create a global TextStyle used to draw the overall text textstyle = new VectorDraw.Render.grTextStyle("Arial"); } void drawoverall(VectorDraw.Render.vdRender render) { double DPIScale=1.0d; //ratio render DPI/ScreenDPI if (render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW_PAPER || render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW) { DPIScale = (double)render.Height / (double)(doc.ActiveLayOut.Printer.LandScape ? doc.ActiveLayOut.Printer.paperSize.Width : doc.ActiveLayOut.Printer.paperSize.Height); } //make the active render unlock so it will always draw using GDIPlus API bool islock = render.IsLock; if (islock) render.UnLock(); //Get the display string string str = System.DateTime.Now.ToShortDateString(); //Calculate the text box with the selecting text style Size. Box textbox = textstyle.GetBaseTextBox(str, null); //create a box that will be drawn in the text background and will be 25% biger tham the text box. Box box = new Box(textbox); box.AddWidth(textbox.Height * 0.25); //calculate a Matrix that will scale and offset the drawing primitives. Matrix m = new Matrix(); double OneMM_DUSize = render.PixelSize * DPIScale * render.DpiY * 1.0d / 25.4; //select the text height to be 10 mm of height. double scale = OneMM_DUSize * 10.0d / textbox.Height; Box rendersize = render.ClipBounds.ToBox(); //select the left offset of the box to be 15 mm of width, and the the bottom offset of the box to be 15 mm. gPoint offset = new gPoint((render.ClipBounds.Xmin + OneMM_DUSize * 15.0d), (render.ClipBounds.Ymin + box.Height * scale + OneMM_DUSize * 15.0d)); if (render.IsPrinting) //taking into consideration the printer hardware margins { offset.x += (OneMM_DUSize * Globals.INCH_MM * doc.ActiveLayOut.Printer.Hardmargins.Left / 100); offset.y += (OneMM_DUSize * Globals.INCH_MM * doc.ActiveLayOut.Printer.Hardmargins.Bottom / 100); } m.ScaleMatrix(scale, scale, scale); m.TranslateMatrix(offset); //select the matrix and draw the primitives render.PushToViewMatrix(); render.PushMatrix(m); render.PushPenstyle(new VectorDraw.Render.vdGdiPenStyle(Color.Brown, 150)); render.DrawSolidBoundBox(this, box); render.PopPenstyle(); render.PushPenstyle(new VectorDraw.Render.vdGdiPenStyle(Color.Blue, 255)); render.DrawString(this, textstyle, null, str, textbox); render.PopPenstyle(); render.PopMatrix(); render.PopMatrix(); if (islock) render.Lock(); } //we use the OnDrawAfter event only when priniting because the OnDrawOverAll is not fired when printing void doc_OnDrawAfter(object sender, VectorDraw.Render.vdRender render) { if (render.IsPrinting && (render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW_PAPER || render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PRINTER_PAPER)) drawoverall(render); } void doc_OnDrawOverAll(object sender, VectorDraw.Render.vdRender render, ref bool cancel) { drawoverall(render); } } }
三. 在HIDE模式下具有更細的線條
問:是否可以在HIDE模式下使用更細的線條?
答:當(dāng)RenderMode為Hidden或ShadeOn時,可以使用FixedShadeOnPenWidth全局屬性來控制線寬,如:
VectorDraw.Render.vdRenderGlobalProperties.FixedShadeOnPenWidth = 0.0f;
默認值為0.016。此值表示以英寸為單位的線寬,通過將其設(shè)置為0,然后在HIDE模式下將1個像素用于“線”。
四. 根據(jù)GridMode = True的縮放動態(tài)更新限制
問:我打開了網(wǎng)格,并將vdDocument.Limits框設(shè)置為視圖的當(dāng)前可見范圍。當(dāng)用戶使用鼠標(biāo)滾輪縮小時,我目前沒有將Limits值更改為當(dāng)前視圖范圍,但希望這樣做。如何捕捉鼠標(biāo)滾輪的事件,以便我可以將網(wǎng)格的限制更改為新的范圍?如何獲得縮放更改事件,這是保持網(wǎng)格覆蓋整個屏幕的最佳方法嗎?
答:執(zhí)行此操作的最佳方法是覆蓋vddocument的draw和drawoverall事件,代碼如下所示:
private void Form1_Load(object sender, EventArgs e) { vdFramedControl.BaseControl.ActiveDocument.OnDraw += new vdDocument.DrawEventHandler(doc_OnDraw); vdFramedControl.BaseControl.ActiveDocument.OnDrawOverAll += new vdDocument.DrawOverAllEventHandler(doc_OnDrawOverAll); } void doc_OnDrawOverAll(object sender, VectorDraw.Render.vdRender render, ref bool cancel) { vdDocument document = sender as vdDocument; UpdateLimits(document.ActiveLayOut); } void doc_OnDraw(object sender, VectorDraw.Render.vdRender render, ref bool cancel) { vdDocument document = sender as vdDocument; UpdateLimits(document.ActiveLayOut); } private void UpdateLimits(vdLayout layout) { if (layout != null && layout.World2ViewMatrix.Zdir.Equals(layout.World2UserMatrix.Zdir)) { Box limitBox = layout.Render.ClipBounds.ToBox(); limitBox.AddWidth(limitBox.Width / 2.0); limitBox.TransformBy((layout.View2WorldMatrix * layout.World2UserMatrix)); layout.Limits.Empty(); layout.Limits.AddBox(limitBox); } }
未完待續(xù)~
好消息!慧都為了感謝大家的支持和關(guān)注,現(xiàn)免費送出30套正版ABViewer軟件~走過路過的同學(xué)千萬不要錯過~