Results 1 to 5 of 5

Thread: I have a problem with TableLayoutPanel columns.

  1. #1

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,904

    I have a problem with TableLayoutPanel columns.

    Hi,

    I have a TableLayoutPanel configured with seven columns, and eleven rows.

    As far as I can tell, the rows are as they should be, but the columns are definitely not.

    In 36 of the cells I have a PictureBox, these are arranged in 6 rows of 6, with a central space dividing them each way into 4 groups of 9 by 9.

    It's the columns that are giving me a problem, so I'll only describe those. Ok, I've checked and double checked the column dimensions in the 'Column and Row Styles' dialogue box, the spacing being: -
    1. 14%: 2. 14%: 3. 14%: 4. 16%: 5. 14%: 6. 14%: 7. 14%:

    All the PictureBoxes have 'Top, Left' Anchors and their Docks are all set to 'Fill'. When I populate the PictureBoxes, the one's in the 7th column (Cell 0.6 for example) all look wider than the rest. So... In the 'Form vb[Design] page I click on each of the PictureBoxes in turn and read off the Size in the Properties dialogue box, 30 of them, those in columns 1, 2, 3, 5 and 6 are all 81,108 but the other 6 in column 7 are all 87,108.

    This isn't the first time I've noticed this, previously I've assumed it was something to do with the small screen on this laptop, but I didn't actually check before.

    So do we have a bug here ? Has it been noted ? I didn't find anything in FAQ or search (except in one of my own threads).

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,254

    Re: I have a problem with TableLayoutPanel columns.

    Quote Originally Posted by Poppa Mintin View Post
    , those in columns 1, 2, 3, 5 and 6 are all 81,108 but the other 6 in column 7 are all 87,108.
    Did you change the controls Margin property?, by default they are set to 3, so if you dock a control in a panel it will have 3 pixels of space on each side of it, set the Margin All to zero and the control would be 6 pixels wider for example.

  3. #3

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,904

    Re: I have a problem with TableLayoutPanel columns.

    Quote Originally Posted by Edgemeal View Post
    Did you change the controls Margin property?
    A good question Edgemeal, that's something I'd not checked. I thought I'd zeroed all the margins and padding as a matter of course, I was somewhat disappointed to find that I had in fact zeroed them all. I really thought you'd found the answer.

    Sadly, from this point of view, all the PictureBoxes have their Margins and Padding set to zero, but I've only found Margin and Padding for the whole TableLayoutPanel, not for individual cells, I imagine that's right. Just to be thorough I've checked the Margin and Padding for everything in the TLP and they are all set to zero. The TLP covers the whole of the form and it's Dock is set to Fill.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,122

    Re: I have a problem with TableLayoutPanel columns.

    Quote Originally Posted by Poppa Mintin View Post
    ...In 36 of the cells I have a PictureBox, these are arranged in 6 rows of 6, with a central space dividing them each way into 4 groups of 9 by 9. ...
    I'm assuming that is 3 by 3, not 9 by 9.

    I wonder how many pixels are in column 4, and if you don't have a picturebox there, whether that makes a difference.
    If the column is empty there might be something going on there, i.e. 16% with no control inside might be a different size compared to 16% with a control inside. I don't know, haven't played with TLPs to try to empirically see if I can determine how is sizes columns give percents and pixels won't often divide evenly.

    The logic on sizing the columns is probably based on an integer size, so if it can't make all the columns the same size exactly, it rounds down to the next lower size and make the columns those sizes, and the last column gets the excess.
    I'm assuming your're filling a 600 pixel wide area of the screen with the TLP. Perhaps that should be six or seven pixels shorter to allow for a pixel border around the cells and rounding of the sizes down to the nearest whole pixel.

    I wonder what would happen if you made the center column 15% and added an 8th column of 1%. If the last column takes up the slack, and you don't use that column, maybe the rest will balance out evenly, but with a little dead space on the right of the TLP.
    Last edited by passel; Dec 24th, 2014 at 02:28 PM.

  5. #5

    Thread Starter
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    1,904

    Re: I have a problem with TableLayoutPanel columns.

    Thanks Passel, yeah, I guess I meant 4 groups of 9, 3 x 3...

    The column that doesn't have a PictureBox has an empty Label, I've found that by adjusting the last column and the gap, I can get the difference down to a virtually unnoticeable 1 pixel. I've done this with three forms, one with 54 PictureBoxes (3-1-3-1-3 columns), the one with 36 (3-1-3 columns), and one with 18 (also 3-1-3), but with the fourth, which only has 9 PictureBoxes in 3 columns and no space, I've managed to get the columns exactly the same by juggling the percentages.

    The 36 PictureBoxes form's 8 column percentages are: -
    1. 14% 2. 14% 3. 14% 4. 17% 5. 14% 6. 14% 7. 13%.
    This gives a central column with 6 other equal columns.

    It's my opinion that we really shouldn't have to do this. In the case of the form with only 3 columns, I tried making the TLP width a multiple of 3 pixels but still the last column was different, by some 7 pixels. I'm using VS 2012 I wonder if this is any better in later versions.

    I considered the 8th (12th, 8th, 4th) column possibility but didn't try it because I'd already done as described above. There's a good chance it'd work but since I'd more or less fixed it, I didn't fancy trying something else in case it didn't work either.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

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