简体   繁体   中英

Highlight Row TableLayoutPanel

I'm trying to make a row of a TableLayoutPanel appear as highlighted when the user selects a cell. The row contains, for example, a Label in one column and a TextBox in the other. I've got this so far (when adding a Label):

Label label = new Label();
label.Text = text;
label.BackColor = Color.Blue;
label.Dock = DockStyle.Fill;
label.Margin = new Padding(0);
label.Anchor = AnchorStyles.Top | AnchorStyles.Left;
table.Controls.Add(label, col, row);

This works well, except there is a bit of whitespace above and to the left of the label. Any idea how to make it so that the entire cell is coloured?

I know about cell painting, but I prefer the above-mentioned approach.

Never mind, I realised that the TableLayoutPanel's border setting was "Inset", so it appeared as though there was whitespace. Changing it to "Single" fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM