PointToScreen 不返回屏幕坐标

PointToScreen not returning screen coordinates

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

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

更进一步,我单击 Tab(键盘按钮)切换到下一个维度,并确保突出显示特定维度。但我担心的是我无法找到突出显示的维度旁边的文本框。

我能够在目视坐标中找到现有线(对应于所选维度)的位置,但是TextBox需要屏幕坐标 准确定位的值。

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

代码:

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 以获得此转换。

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

提前致谢

苏拉吉

您使您的对象 (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