0

I am using EyeShot 12. I am creating a rectangle using EyeShot Line Entity, it has 2 dimensions along length and breadth.

My functionality involves changing the Dimension Text by using the action->SelectByPick, then picking anyone of the dimension and changing its value by bringing up a TextBox so that user can add the value. Here the TextBox pops-up on the location of mouse pointer.

Going further I click on Tab (keypad button) to switch to next dimension and also making sure that particular Dimension gets highlighted. But my concern is I am unable to locate the TextBox next to that highlighted dimension.

I am able to locate the position of existing Line(corresponding to the selected dimension) in Eyeshot coordinates but TextBox requires screen coordinates value for Positioning it exactly.

So I am using control.PointToScreen to convert eyeshot coordinates into screen but it return a Point which is same as to the Eyeshot coordinates.

code:

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);
    }

I looked for other results but everyone triggers to PointToScreen to get this convertion.

Hoping somebody can point what I am doing.

Thanks in advance

Suraj

Timo Salomäki
  • 7,099
  • 3
  • 25
  • 40
STR
  • 23
  • 4
  • The line `model1.Controls.Add(tb);` makes textbox a child control of `model1` which means that `tb.Location` property needs to be in client coordinates of `model1` and not in a screen coordinates. – Sergey Shevchenko Oct 11 '19 at 08:11
  • And btw, why do you use such a weird conversion as `int.Parse(midpt.X.ToString())`? Can't you just cast directly to integer `(int)midpt.X`? – Sergey Shevchenko Oct 11 '19 at 08:13
  • @SergeyShevchenko thanks. I did the changes `System.Drawing.Point clientLocation = model1.PointToClient(new System.Drawing.Point((int)midpt.X, (int)midpt.Y));` `tb.Location = clientLocation;` but still the coordinates are coming at the top left corner of screen while Lines having eyeshot coordinates as (0,0) -> (50,0) . And after conversion I get the same coordinate values. – STR Oct 11 '19 at 08:51
  • To place a textbox inside `model1` you need to convert `midpt` coordinates into `model1` client coordinates. For that you need to know what coordinates `midpt` currently has (is that a screen, client or any custom coordinates). Btw, what is a type of `model1` variable? – Sergey Shevchenko Oct 11 '19 at 09:24
  • `midpt` has client coordinates and model1 is type of Model Form1. – STR Oct 11 '19 at 09:37
  • Are you sure? Isn't it a so called world coordinates? Can you try something like `var screenPt = model1.Camera.WorldToScreen(midpt);` and then `var clientPt = model1.PointToClient(screenPt)`. Then use `clientPt` as a location for editbox. – Sergey Shevchenko Oct 11 '19 at 09:43
  • It has one more parameter, WorldToScreen(Point3D point, **int[] viewFrame**); What to give for this viewFrame ? – STR Oct 11 '19 at 11:20
  • According to documentattion - viewports collection – Sergey Shevchenko Oct 11 '19 at 11:38
  • Instead of that you can try `var screenPt = model1.Viewports[model1.ActiveViewport].WorldToScreen(midpt)`, this will use only a current viewport – Sergey Shevchenko Oct 11 '19 at 11:41

1 Answers1

0

You made your object (TextBox) a child of the ViewportLayout therefore you need the point relative to it. But the controls are not in the world coordinate but screen coordinate based on their parent.

What you actually need is two (2) conversion.

// 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
Franck
  • 4,438
  • 1
  • 28
  • 55