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

11 REPLIES 11

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

 

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

Creator
Creator

Hi DianaG,

 

is there a possibility to fix/attach this opened form to the choosen object? I cannot find any solution...

 

Best regards

Jan

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

Siemens Legend Siemens Legend
Siemens Legend

Hi,

Do you mean that you want to move the form, as an object moves? if so, then you can register to the object's AbsoulteLocationChange event and move your window.

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

Creator
Creator

Hi,

 

I've tried to attach the form to an object (e.g. a robot) so I can move (zoom, rotate or navigate...) in the GraphicViewer and the form is still attached to the object..

In other words (or in steps):

1. click the button in the toolbar > each object gets a single 'sign' as a form with machine data, located near by the object

2. I like to move into the GraphicViewer while the single signs should stay at their locations near to the objects

 

Is it clear? Hard to explain Smiley Very Happy

 

Best regards,

Jan

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

Siemens Legend Siemens Legend
Siemens Legend

Why do you need form? Did you consider using Notes? they can be easily attached to an object.

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

Creator
Creator

Hi,

 

I think I'll need forms to show energy data as diagrams (not just a text).

 

Best regards,

Jan

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

Siemens Legend Siemens Legend
Siemens Legend

Hi,

Do you want that the content of the diagrm will always be shown, or only when the user clicks on it?

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

Creator
Creator

The content should be shown all the time (if possible), without any click event.