0

I want to know, Can I get the location of other control from a particular control? Tried to search on the internet and found C# Get a control's position on a form but didn't understand it properly. Here's an example:

Form with a four-button grid

As you can see I have used 4 buttons, Now I want to know Which control is Left/Right/Up/Down to Button 3.

Niket
  • 11
  • 3
  • On the client, using JavaScript? – Marcel May 20 '22 at 06:46
  • 1
    No, it's c# winforms – Niket May 20 '22 at 06:47
  • Sure, you can calculate this based on the `Location` property of the controls. But are those controls created dynamically at run-time? Because, otherwise, your code should know this information, to begin with. An alternative that _might_ work here would be to rely on the `TabIndex` property (after you set it properly, of course). – 41686d6564 stands w. Palestine May 20 '22 at 06:47
  • Can you tell us exactly what you're trying to achieve by getting this information? – 41686d6564 stands w. Palestine May 20 '22 at 06:49
  • As a side, note, please don't use tags in the title. That's what tags are for. – 41686d6564 stands w. Palestine May 20 '22 at 06:54
  • I am using ETO (https://github.com/picoe/Eto) Library, by which we can create cross-Platform application. So I have a desktop application created in Winforms and now I'm running that app in Linux using GTK tool with same code of Winforms but use ETO which migrate my winform code into GTK code. So in GTK platform, all the controls are overlapping. Hence, I want to know the location of the control grammatically so I can move them by adding extra points in code in ETO. So I need logic in winforms how to do this and I'll convert it into ETO @41686d6564standsw.Palestine – Niket May 20 '22 at 07:05
  • Add your Controls (Buttons or whatever) to a TableLayoutPanel or FlowLayoutPanel (the former appears to be more appropriate in your case) -- Handling nested Containers to layout Controls is quite important. – Jimi May 20 '22 at 08:03

1 Answers1

-2

It's not possible on the server side to determine how "near", in terms of screen position, two controls will be rendered on the client side.

It might depend on the Browser, used plugins (which e.g. load additional CSS or Javascript)

You have two options

  • Calculate the geography on the client, then do what you want
  • Try your best and provide a HTML structure that is likely to be rendered the way you want it.

Maybe, in your case, a HTML <table> layout is what you need, given the example.

Marcel
  • 15,039
  • 20
  • 92
  • 150