C# 指向屏幕不返回屏幕坐标

C# 指向屏幕不返回屏幕坐标,c#,winforms,eyeshot,C#,Winforms,Eyeshot,我用的是EyeShot 12。我正在使用EyeShotLine实体创建一个矩形,它沿长度和宽度有两个维度 我的功能包括使用action->SelectByPick更改维度文本,然后选择维度中的任何一个,并通过打开文本框来更改其值,以便用户可以添加值。在这里,文本框弹出在鼠标指针的位置上 更进一步,我单击选项卡(键盘按钮)切换到下一个维度,并确保突出显示特定维度。但我担心的是,我无法找到突出显示维度旁边的文本框 我能够在视野坐标中定位现有线路的位置(对应于所选尺寸),但TextBox需要屏幕坐标值

我用的是EyeShot 12。我正在使用EyeShotLine实体创建一个矩形,它沿长度和宽度有两个维度

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

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

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

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

代码:

我寻找其他的结果,但每个人都会触发指向屏幕的按钮来获得这个转换

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

提前谢谢

Suraj

您将对象(
TextBox
)设置为
视口布局的子对象,因此您需要相对于它的点。但是控件不在世界坐标系中,而是基于其父控件的屏幕坐标系中

您实际需要的是两(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

model1.Controls.Add(tb)
使textbox成为
model1
的子控件,这意味着
tb.Location
属性需要位于
model1
的客户端坐标中,而不是屏幕坐标中。顺便问一下,为什么要使用像
int.Parse(midpt.X.ToString())这样奇怪的转换?你就不能直接对integer
(int)midpt.X进行强制转换吗?@SergeyShevchenko谢谢。我做了更改
System.Drawing.Point clientLocation=model1.PointToClient(新的System.Drawing.Point((int)midpt.X,(int)midpt.Y))
tb.Location=clientLocation但坐标仍然位于屏幕的左上角,而视线坐标为(0,0)->(50,0)的线条。转换后,我得到相同的坐标值。要在
model1
中放置一个文本框,需要将
midpt
坐标转换为
model1
客户坐标。为此,您需要知道当前的坐标
midpt
(是屏幕坐标、客户端坐标还是任何自定义坐标)。顺便说一句,什么是
model1
变量类型?
midpt
有客户坐标,model1是modelform1的类型。感谢您提供这一详细的答案。而且@sergey也向我提出了同样的建议。
// 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