×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how can I reposition a control in relative coordinates?

how can I reposition a control in relative coordinates?

how can I reposition a control in relative coordinates?

(OP)
Hello,

I have a container that has three panels in it: HeaderPanel, ControlPanel, ButtonPanel. They are all vertically aligned in that order.

I'm having trouble repositioning the ButtonPanel. Any time I add a control to the ControlPanel, I have to shift the ButtonPanel down to make room for the control so that it's visible.

I try repositioning the ButtonPanel like this:

ButtonPanel.Location = new Point(ButtonPanel.Location.X, ControlPanel.Location.Y + ControlPanel.Height);

But this does not position the ButtonPanel where I expect it to be.

I tried experimenting with things like this:

ButtonPanel.Location = new Point(ButtonPanel.Location.X, 1);

in which case the ButtonPanel didn't show up at all.

Then it occurred to me that this repositioning might be setting the location in absolute coordinates (which means that setting Y to 1 would put the ButtonPanel way above its container, and therefore not visible). I tested this with incremental values for Y until the bottom edge of the ButtonPanel finally started showing up within its container.

So I'm wondering why is it that when I get the Y value of ControlPanel, it gives it to me in relative coordinates (i.e. relative to its container) but if I try to set the location of the ButtonPanel (or any panel I presume), it sets it to absolute coordinates?

How can I change this so that the coordinates I give it when I'm repositioning the control are relative to the control's container?

RE: how can I reposition a control in relative coordinates?

As far as I know it should always be relative to the container control.

I assume HeaderPanel, ControlPanel, and ButtonPanel all share a common container (the Form perhaps, or maybe another panel)?

Here is what most likely happened when you slowly increased Y until you saw the bottom edge: It was relative to the container control (1 being the TOP) - but you could not see it because it ButtonPanel was behind the HeaderPanel and the ControlPanel.

Quote:


ButtonPanel.Location = new Point(ButtonPanel.Location.X, ControlPanel.Location.Y + ControlPanel.Height);

But this does not position the ButtonPanel where I expect it to be.

When you say that - do you mean that it is slightly higher than what you expected it to be? This is easily caused by not taking into account the Margin of both the ButtonPanel and the ControlPanel, plus any additional spacing you may have had during the initial layout of those panels. So you might see something like this:

CODE

ButtonPanel.Location = new Point(ButtonPanel.Location.X, ControlPanel.Location.Y + ControlPanel.Height + ControlPanel.Margin.Bottom + ButtonPanel.Margin.Top + anyExistingSpace); 

Another simpler way to keep them all together and automatically adjust is to stick HeaderPanel, ControlPanel, and ButtonPanel all within a FlowLayoutPanel - with the FlowDirection set to TopDown. Then when the height of ControlPanel changes, ButtonPanel should automatically be pushed down.

RE: how can I reposition a control in relative coordinates?

(OP)
Thanks for that Borvik,

Sorry for not replying earlier but I got busy and forgot that I posted this.

In any case, the problem is solved (not by me though so I'm not sure how it was solved).

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close