如何在不符合TableLayoutPanel规则的情况下在特定位置(以像素为单位)添加新元素? [英] How to add new element in a specific position (in pixels) without complying with TableLayoutPanel rules?

查看:169
本文介绍了如何在不符合TableLayoutPanel规则的情况下在特定位置(以像素为单位)添加新元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将TableLayoutPanel设置为用于组织输入的布局.直到我意识到我必须添加不应在表中特定单元格中的新元素(这必须跨表单元格,但单元格必须保持原样)之前,这是一个好主意.

I have set a TableLayoutPanel as a layout to organise my inputs. That was a good idea up to the moment when I realised that I had to add new elements that are not supposed to be in a specific cell in the table (They must span across table cells, but cells have to remain untouched)

推荐答案

您需要为控件设置开始单元格

You need to set the starting cell for the control

Panel pan = new Panel() {BackColor = Color.Red, Parent = tableLayoutPanel1 };

要么这样:

tableLayoutPanel1.SetCellPosition(pan, new TableLayoutPanelCellPosition(1, 2));

或类似这样:

tableLayoutPanel1.SetColumn(pan, 1);
tableLayoutPanel1.SetRow(pan, 2);

然后您可以从该位置设置跨度,如下所示:

Then you can set the spans from that position like this:

tableLayoutPanel1.SetColumnSpan(pan, 3);
tableLayoutPanel1.SetRowSpan(pan, 2);

最后,您可以通过设置控件的Margin:

And finally you can fine-tune the position at pixel-level by setting the control's Margin:

  pan.Margin = new Padding(55, 5, 0, 0);

但是请注意,跨范围的作用就像一个单元格:它只能包含一个控件,因此您不能将任何其他 Control放置在跨度中范围!如果您需要更多在相同范围内的控件,则需要嵌套它们全部放在Panel或其他Container中!

Note however that a spanned range acts like a cell: It can only contain one control, so you cannot place any other Control in the spanned range! If you need more controls in the same range you need to nest them all in a Panel or other Container!

这篇关于如何在不符合TableLayoutPanel规则的情况下在特定位置(以像素为单位)添加新元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆