新手入門必看:VectorDraw 常見問題整理大全(三)
VectorDraw Developer Framework(VDF)是一個用于應用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印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)最新版下載】
一. 使用vdScrolableControl獲取實體并在vdPropertyGrid中顯示其屬性
問:如何使用vdScrolableControl獲取實體并在vdPropertyGrid中顯示其屬性?
答:可以試試像這樣的代碼:
private void Form1_Load(object sender, EventArgs e) { AddLayoutEntities(); vdSC.BaseControl.vdMouseClick += new VectorDraw.Professional.Control.MouseClickEventHandler(BaseControl_vdMouseClick); } void BaseControl_vdMouseClick(MouseEventArgs e, ref bool cancel) { VectorDraw.Professional.vdPrimaries.vdFigure fig; VectorDraw.Geometry.gPoint pt = vdSC.BaseControl.ActiveDocument.CursorPosCCS(e.Location); VectorDraw.Geometry.gPoint p1 = vdSC.BaseControl.ActiveDocument.World2PixelMatrix.Transform(pt as VectorDraw.Geometry.gPoint); Point location = new Point((int)p1.x, (int)p1.y); fig = vdSC.BaseControl.ActiveDocument.ActiveLayOut.GetEntityFromPoint(location, vdSC.BaseControl.ActiveDocument.ActiveLayOut.Render.GlobalProperties.PickSize, false); if (fig == null) { vdPGrid.SelectedObject = vdSC.BaseControl.ActiveDocument; this.Text = "NO Entity clicked"; } else { vdPGrid.SelectedObject = fig; this.Text = "Entity clicked"; } }
二. 讀取附加到polyhatch對象的折線
問:如何讀取附加到polyhatch對象的折線?
答:您可以從hatch(孵化)中獲取vdCurves,如下所示。請注意,填充對象可能包含vdCircle,vdArc以及通常所有類型的vdCurves。孵化是vdPolyhatch對象。
foreach (VectorDraw.Professional.vdCollections.vdCurves var in hatch.PolyCurves) { foreach (VectorDraw.Professional.vdFigures.vdCurve var1 in var) { VectorDraw.Professional.vdFigures.vdPolyline poly1 = var1 as VectorDraw.Professional.vdFigures.vdPolyline; if (poly1 != null) MessageBox.Show("Found Polyline"); } }
三. 重寫VectorDrawBaseControl的DrawBackground事件
問:如何重寫VectorDrawBaseControl的DrawBackground事件,以便將Image繪制到Background?
答:以下示例覆蓋VectorDrawBaseControl的DrawBackground和vdScroll事件,以便在rendermode is Wire2d時將圖像繪制為背景。
Bitmap m_Bitmap; private void Form1_Load(object sender, EventArgs e) { vdFramedControl.BaseControl.DrawBackground += new VectorDraw.Professional.Control.DrawBackgroundEventHandler(BaseControl_DrawBackground); vdFramedControl.BaseControl.vdScroll += new VectorDraw.Professional.Control.ScrollEventHandler(BaseControl_vdScroll); //create a bitmap object at runtime m_Bitmap = new Bitmap(vdFramedControl.BaseControl.Size.Width, vdFramedControl.BaseControl.Size.Height); Graphics g = Graphics.FromImage(m_Bitmap); g.Clear(vdFramedControl.BaseControl.ActiveDocument.Palette.Background); g.DrawString("VDraw", SystemFonts.DefaultFont, Brushes.Red, new PointF(vdFramedControl.BaseControl.Size.Width / 2, vdFramedControl.BaseControl.Size.Height/2)); g.Dispose(); } //override the vdScroll event in order the pan and scroll draw the background properly. void BaseControl_vdScroll(object sender, ref double cx, ref double cy, ref bool cancel) { vdRender render = sender as vdRender; render.ViewCenter += new gPoint(cx, cy); vdFramedControl.BaseControl.ActiveDocument.Redraw(false); } void BaseControl_DrawBackground(object sender, VectorDraw.Render.vdRender render, ref bool cancel) { System.Diagnostics.Debug.WriteLine("DrawBackground"); if (m_Bitmap == null) return; if (!render.IsWire2d) return;//the following code is working only when 3d render is not active render.UnLock(); Graphics g = render.graphics; if (g == null) return; g.Clear(render.BkColor); g.DrawImage(m_Bitmap, new Point(0, 0)); g.DrawLine(Pens.Red, new Point(0, 0), new Point(render.Width, render.Height)); render.Lock(); cancel = true; }