Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

How to place a Windows Form at a choosen point?

Creator
Creator

Hello everyone!

 

Using C#:

I'm trying to fix a TxForm while opening at the place I've choosen by click in graphic viewer (i.e. at an robot; like in the picture attached).

The Form should then be fixed at this place like a gripper...

 

Is there anyone who could help?

 

Best regards,

Jan

2 REPLIES

Re: How to place a Windows Form at a choosen point?

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi JanOle,

 

You need to register for the MouseUp event of the Graphic viewer and then you can calculate the location using the event arguments + Graphic Viewer position. Here is an example. Don't forget to unregister from the MouseUp event.

public override void Execute(object cmdParams)
        {
            TxGraphicViewer.MouseUp += TxGraphicViewer_MouseUp;
        }

        private void TxGraphicViewer_MouseUp(object sender, TxGraphicViewer_MouseEventArgs args)
        {
            int x = args.X;
            int y = args.Y;


            Rectangle bounds = TxApplication.ViewersManager.GraphicViewer.ContainerWindow.Bounds;
            Form1 form = new Form1();            
            form.Location = new System.Drawing.Point(bounds.Left + x, bounds.Top + y);
            form.FormClosed += Form_FormClosed;
            form.Show();
        }

Best Regards,

DianaG

Re: How to place a Windows Form at a choosen point?

Creator
Creator

Hi DianaG,

 

thanks a lot, works fine (just changed 'MouseUp' in 'MouseDown' to open the form while clicking).

 

Have a nice weekend, best regards,

 

Jan