Click here to Skip to main content
14,922,577 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a new entry in this TableLayoutPanel for adding and removing users for a system. I am trying to add a button and a label. I have successfully created the button and the label but when I go to run it, they are top left aligned. I am trying to center align them so it looks like the other table entries. Below is the code I have so far. This is the entry I am trying to create. I just need them to be aligned in the middle of the cell when I create the entry. If this is even possible.

What I have tried:

private void button1_Click(object sender, EventArgs e)
{
    UserTable.RowStyles.Add(new RowStyle(SizeType.Percent, 14));
    UserTable.Controls.Add(new Label() { Text = "user5" }, 0, 5);
    UserTable.Controls.Add(new Button() { Text = "remove" }, 1, 5);
}
Posted
Updated 3-May-21 19:34pm

1 solution

Try:
C#
UserTable.Controls.Add(new Label() { Text = "user5", Anchor = AnchorStyles.None }, 0, 5);
UserTable.Controls.Add(new Button() { Text = "remove", Anchor = AnchorStyles.None }, 1, 5);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900