none
How to merge cells in TableLayoutPanel?

    Question

  • Hello.
    I'm using VS 2008 and .NET 3.5 in Windows XP.

    I created a table using TableLayoutPanel class. I'd like to create a shape something like
    -------------------------------------------------------|
    |   merged      |                                              |
    |     cell          |-------------------------------------|
    |                    |                                              |
    |------------------------------------------------------|

    There will be a Label in the merged cell. But I don't know how to merge cells.

    As a workaround, I set all labels' Dock property to DockStyle.Fill, set its Margin property to new System.Windows.Forms.Padding(0), and set its RowSpan to 2. Then the cell looked like a merged cell, but there still appear tiny glitches in the row & column boundaries. So now it looks like:

    -------------------------------------------------------|
    |   merged      |                                              |
    |-    cell         -|-------------------------------------|
    |                    |                                              |
    |------------------------------------------------------|

    (Do you recognize the glitches in row boundaries?)

    How can I remove those glitches and make the cell appear to be a truly *merged* cell?

    Thanks!
    • Moved by CoolDadTxMVP Monday, April 13, 2009 1:29 PM Moved
    Monday, April 13, 2009 5:27 AM

Answers

  • Hi nyam,

    I can see what you called "glitches" at the first time. However, I can remove this by setting the Margin property of the Label.

    You can do as the following steps:

    • Choose the Label control, and switch to the propertygrid.
    • Expand Margin property.
    • Set the Top, Bottom, Left,Right to zero.
    The following is my test project , if refer to it if you have difficulty.

    If the problem can't be solved on your side, please feel free to let me know.


    Best regards,
    Bruce Zhou



    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by nyam Thursday, April 16, 2009 1:34 AM
    Tuesday, April 14, 2009 5:51 AM

All replies

  • Hi nyam,

    I can see what you called "glitches" at the first time. However, I can remove this by setting the Margin property of the Label.

    You can do as the following steps:

    • Choose the Label control, and switch to the propertygrid.
    • Expand Margin property.
    • Set the Top, Bottom, Left,Right to zero.
    The following is my test project , if refer to it if you have difficulty.

    If the problem can't be solved on your side, please feel free to let me know.


    Best regards,
    Bruce Zhou



    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by nyam Thursday, April 16, 2009 1:34 AM
    Tuesday, April 14, 2009 5:51 AM
  • Thank you Bruce.Zhou!

    Thank you for your test project. What I did was exactly the same as what you did. I set all margins to 0s.
    But there are still *tiny* glitches in there, you may notice them as well if you closely look at the left border of label1 in your test project, where the rows change. In your test project there are only two of them, but my TableLayoutPanel had many rows and columns so I could recognize them.

    Well, but I think these can be negligible unless someone's too picky.

    Thank you!
    Thursday, April 16, 2009 1:34 AM
  • You are welcome. I am not sure if you are running the same version operating system as me. The test project runs well in Windows Server 2003 which I am just using. I can't see the tiny glitches even I zoom in the Form using the tool. However, even if there is any, these can be negligible as you said.


    Best regards,
    Bruce Zhou
    Please mark the replies as answers if they help and unmark if they don't.
    Thursday, April 16, 2009 1:45 AM