VDF常見問題整理(二十九):如何保存和加載圖形的OsnapMode值?
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
點(diǎn)開本篇文章,是否對矢量圖形工具感興趣呢?來看看最新的矢量圖形工具測評吧!點(diǎn)擊此處>>即可直達(dá)哦!
問:
如何在圖形中保存和加載OsnapMode值?我需要保存osnap模式的值,然后在打開圖形時(shí)讀取該值并將其重新設(shè)置。
答:
通過將xproperty添加到包含OSNAPMode值的0層,您可以輕松地做到這一點(diǎn),無法刪除第0層,因此該xproperty也將不會被其他應(yīng)用程序刪除。
請參見下面的示例代碼:
private void button3_Click(object sender, EventArgs e) { vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument; doc.New(); vdCircle cir = new vdCircle(doc, new gPoint(2, 2), 2); doc.Model.Entities.AddItem(cir); // JUST add a simple object doc.osnapMode = OsnapMode.TANG | OsnapMode.CEN | OsnapMode.END ; // set the osnap mode string str_Osnap = doc.osnapMode.ToString(); MessageBox.Show(str_Osnap); vdLayer lay0 =doc.Layers.FindName("0"); // always exist in the document and cannot be deleted VectorDraw.Professional.vdObjects.vdXProperty xprop = new VectorDraw.Professional.vdObjects.vdXProperty(); xprop.Name = "str_Osnap_Mode";// and add it to layer 0 as xproperty xprop.PropValue = str_Osnap; lay0.XProperties.AddItem(xprop); doc.SaveAs(@"c:\test.vdcl"); } private void button4_Click(object sender, EventArgs e) { vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument; doc.New(); doc.OnAfterOpenDocument += new vdDocument.AfterOpenDocument(doc_OnAfterOpenDocument); doc.Open(@"c:\test.vdcl"); } void doc_OnAfterOpenDocument(object sender) { vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument; vdLayer lay0 = doc.Layers.FindName("0"); VectorDraw.Professional.vdObjects.vdXProperty xprop = lay0.XProperties.FindName("str_Osnap_Mode"); if (xprop != null) { doc.osnapMode = OsnapMode.NONE; string value = xprop.PropValue as string; if (value.Contains("END")) doc.osnapMode = doc.osnapMode | OsnapMode.END; if (value.Contains("MID")) doc.osnapMode = doc.osnapMode | OsnapMode.MID; if (value.Contains("CEN")) doc.osnapMode = doc.osnapMode | OsnapMode.CEN; if (value.Contains("INS")) doc.osnapMode = doc.osnapMode | OsnapMode.INS; if (value.Contains("PER")) doc.osnapMode = doc.osnapMode | OsnapMode.PER; if (value.Contains("NEA")) doc.osnapMode = doc.osnapMode | OsnapMode.NEA; if (value.Contains("INTERS")) doc.osnapMode = doc.osnapMode | OsnapMode.INTERS; if (value.Contains("NODE")) doc.osnapMode = doc.osnapMode | OsnapMode.NODE; if (value.Contains("QUA")) doc.osnapMode = doc.osnapMode | OsnapMode.QUA; if (value.Contains("TANG")) doc.osnapMode = doc.osnapMode | OsnapMode.TANG; if (value.Contains("APPARENTINT")) doc.osnapMode = doc.osnapMode | OsnapMode.APPARENTINT; if (value.Contains("EXTENSION")) doc.osnapMode = doc.osnapMode | OsnapMode.EXTENSION; if (value.Contains("ALL")) doc.osnapMode = doc.osnapMode | OsnapMode.ALL; if (value.Contains("DISABLE")) doc.osnapMode = doc.osnapMode | OsnapMode.DISABLE; } }
對于以上問答,如果您有任何的疑惑都可以在評論區(qū)留言,我們會及時(shí)回復(fù)。此系列的問答教程我們會持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
熱門文章推薦:
點(diǎn)擊此處還有VectorDraw Developer Framework的demo示例等著你來體驗(yàn)哦!
如果您對想要購買正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關(guān)問題。
關(guān)注慧聚IT微信公眾號 ???,了解產(chǎn)品的最新動態(tài)及最新資訊。