首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PointToScreen不返回屏幕坐标

PointToScreen不返回屏幕坐标
EN

Stack Overflow用户
提问于 2019-10-11 07:26:17
回答 1查看 695关注 0票数 0

我使用的是EyeShot 12,我用EyeShot Line实体创建了一个矩形,它的长度和宽度都是二维的。

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

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

我能够在视区坐标中定位现有线的位置(对应于所选的尺寸),但是TextBox需要屏幕坐标值来精确定位它。

因此,我使用control.PointToScreen将眼点坐标转换为屏幕,但它返回的点与视点坐标相同。

代码:

代码语言:javascript
复制
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来获得这个转换。

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

提前感谢

苏拉杰

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-11 12:50:36

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

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

代码语言:javascript
复制
// 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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58336206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档