0

我正在使用 EyeShot 12。我正在使用 EyeShot Line Entity 创建一个矩形,它沿长度和宽度有 2 个维度。

我的功能包括使用 action->SelectByPick更改维度文本,然后选择任何维度并通过调出文本框来更改其值,以便用户可以添加值。这里TextBox在鼠标指针的位置上弹出。

更进一步,我单击选项卡(键盘按钮)以切换到下一个维度,并确保突出显示特定的维度。但我担心的是我无法在该突出显示的维度旁边找到 TextBox。

我能够在Eyeshot 坐标中定位现有 Line 的位置(对应于所选尺寸),但TextBox 需要 屏幕坐标值才能准确定位它。

所以我使用control.PointToScreen将视野坐标转换为屏幕,但它返回一个与视野坐标相同的点。

代码:

foreach (Entity ent in model1.Entities)      
{
    if (ent.Selected)
    {
        Line lin = (Line)ent;

        Point3D midpt = lin.MidPoint;

        string newpt1X = midpt.X.ToString();
        string newpt1Y = midpt.Y.ToString();

        System.Drawing.Point startPtX = model1.PointToScreen(new 
        System.Drawing.Point(int.Parse(newpt1X) + 20, int.Parse(newpt1Y) + 20));

        TextBox tb = new TextBox();
        tb.Text = "some text";
        tb.Width = 50;
        tb.Location = startPtX;
        model1.Controls.Add(tb);
    }

我寻找了其他结果,但每个人都会触发 PointToScreen 来获得这种转换。

希望有人能指出我在做什么。

提前致谢

苏拉杰

4

1 回答 1

0

您使您的对象 ( TextBox) 成为 的子对象,ViewportLayout因此您需要相对于它的点。但是控件不在世界坐标中,而是基于其父级的屏幕坐标。

您实际需要的是两 (2) 次转换。

// first grab the entity point you want
// this is a world point in 3D. I used your line entity
// of your loop here
var entityPoint = ((Line)ent).MidPoint;

// now use your Viewport to transform the world point to a screen point
// this screen point is actually a point on your real physical monitor(s)
// so it is very generic, it need further conversion to be local to the control
var screenPoint = model1.WorldToScreen(entityPoint);

// now create a window 2d point
var window2Dpoint = new System.Drawing.Point(screenPoint.X, screenPoint.Y);

// now the point is on the complete screen but you want to know
// relative to your viewport where that is window-wise
var pointLocalToViewport = model1.PointToClient(window2Dpoint);

// now you can setup the textbox position with this point as it's local
// in X, Y relative to the model control.
tb.Left = pointLocalToViewport.X;
tb.Top = pointLocalToViewport.Y;

// then you can add the textbox to the model1.Controls
于 2019-10-11T12:50:36.703 回答