VDF常見問題整理(四十四):如何在多視圖布局中獲取活動視口的屏幕坐標(biāo)?
VectorDraw Developer Framework(VDF)是一個用于應(yīng)用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問:
如何獲取vdLayoutSplit的活動視口左下角和右上角的顯示坐標(biāo)(像素)。我想在文檔的鼠標(biāo)按下事件下檢查鼠標(biāo)位置是否在活動視口內(nèi)。
答:
使用包含四個視口的LayoutSplit的圖形(mv.vdcl)嘗試以下代碼:
private void button1_Click(object sender, EventArgs e) { vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument; doc.New(); doc.Open(@"c:\test\mv.vdcl");// load a drawing that contains multiviews doc.ActiveLayOut = doc.LayOuts.FindName("Four_Left"); // set the active layout doc.Redraw(true); doc.ActiveLayOut.ActiveViewPort = doc.ActiveLayOut.Entities[1] as vdViewport; //set the activeViewport vdViewport vLeft = doc.ActiveLayOut.ActiveViewPort; // for this viewport we will get its coordinates in screen pixels Box bbox = vLeft.BoundingBox; // in World Coordinate System gPoint LR = bbox.LowerRight; // in World CS gPoint UL = bbox.UpperLeft;// in World CS Matrix matView2Pixel = doc.ActiveLayOut.Pixel2ViewMatrix.GetInvertion(); Matrix matWorld2View=doc.ActiveLayOut.World2ViewMatrix; UL = matWorld2View.Transform(UL); // from World CS to View CS UL = matView2Pixel.Transform(UL); // From View CS to Pixels LR = matWorld2View.Transform(LR); // from World CS to View CS LR = matView2Pixel.Transform(LR); // From View CS to Pixels Rectangle rc = new Rectangle(new Point((int)UL.x,(int)UL.y),new Size((int)(LR.x-UL.x),(int)(LR.y-UL.y)));// this is the viewport rectangle Rectangle onScreen = vdFramedControl1.BaseControl.RectangleToScreen(rc); // from VDF control's pixels to screen pixels // here you get the Upper/left point in screen pixels (onScreen.Location) // and the lower-right point like OnScreen.X+OnScreen.Width , OnScreen.Y+onScreen.Height // Display the results: doc.Prompt("\r\n ---- Active Viewport in Screen pixels, ------"); doc.Prompt(null); doc.Prompt("\r\n UpperLeft point: " + onScreen.Location.ToString()); doc.Prompt(null); doc.Prompt("\r\n LowerRight point: X=" + (onScreen.X + onScreen.Width).ToString() + " , Y=" + (onScreen.Y + onScreen.Height).ToString()); doc.Prompt(null); }
請檢查此代碼中的注釋,以了解其計(jì)算方式并根據(jù)您的需要定制此代碼。還請檢查vdf.chm幫助文件以及這些方法/屬性的主題,以了解其用法。
以上問答,如果您有任何的疑惑都可以在評論區(qū)留言,我們會及時回復(fù)。此系列的問答教程我們會持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
熱門文章推薦:
如果您對想要購買正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關(guān)問題。
關(guān)注慧聚IT微信公眾號 ???,了解產(chǎn)品的最新動態(tài)及最新資訊。