CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Posts
    63

    how do I reposition controls in relative coordinates

    Hello,

    Please have a look at my screen capture:

    Name:  FlowLayoutPanel.jpg
Views: 86
Size:  15.4 KB

    I'm having trouble repositioning the ButtonPanel (in blue). Any time I add a control to the ControlPanel (in green), 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?
    Last edited by gib65; July 3rd, 2012 at 11:59 AM.

  2. #2
    Join Date
    Jun 2011
    Location
    Buenos Aires, Argentina
    Posts
    130

    Re: how do I reposition controls in relative coordinates

    I have found a new best friend in GUI design using a TableLayoutPanel. It's basically a grid that will allow you to add controls to each cell. and allow you to add Rows/Columns and set the size of each of them to absolute widths/heights or percentages of the forms total size. Say you have a DataGridView and an MSChart, you'd have (for example) one Row and two Columns. You can set the Row's Heigth to 100%, the first Column (the one with the DGV) width to 200 absolute and the second Column's width to 100%. That way when the form resizes the first column only grows in height, and the chart uses all the remaining space to present graphs better, etc.

    If you're adding controls at runtime, you can always add new rows/columns to the TLP and set your new control to it. You completely forget about re-positioning. Check row/columnspan too, very useful properties.

  3. #3
    Join Date
    Nov 2011
    Posts
    63

    Re: how do I reposition controls in relative coordinates

    Thanks for that Nikel,

    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured