仅为 TableLayoutPanel 单元格绘制外边框 [英] Draw only outer border for TableLayoutPanel Cells

查看:190
本文介绍了仅为 TableLayoutPanel 单元格绘制外边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我有 3 行和 5 列,我正在使用 TableLayoutPanel.我只想绘制整个面板的外边框.默认情况下,面板提供 CellBorderStyle,它将所有侧边框添加到所有可用单元格.有什么办法可以只设置外部边界吗?

I am using the TableLayoutPanel for example if I have 3 rows and 5 columns. I want to draw only the outer border for the entire panel. By default the the panel provides CellBorderStyle which adds all side borders to all the cells available. Is there any way where we can set only outside borders?

我在下面提供了示例代码.

I have provided a sample code below.

    TableLayoutPanel tblPanel = new TableLayoutPanel;
    tblPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
    Label lblName;
    TextBox txtName;
    Button btnAdd;
    int colCnt = 0;
    for(int rw =0; rw < 3; rw++)
    {
            lblName = new Label();
            lblName.Name = "mylabel" + rw.ToString();
            tblPanel.Controls.Add(lblName, colCnt, rw);
            colCnt++;

            txtName = new TextBox();
            txtName.Name = "mytext" + rw.ToString();
            tblPanel.Controls.Add(txtName, colCnt, rw);
            colCnt++;

            btnAdd = new Button();
            btnAdd.Name = "mybutton" + rw.ToString();
            tblPanel.Controls.Add(btnAdd, colCnt, rw);

            colCnt = 0;
    }

推荐答案

TableLayoutPanel 实际上支持 BorderStyle 属性,这正是您想要的.例如:

TableLayoutPanel does in fact support the BorderStyle property, which is what you want. For example:

tableLayoutPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

https://msdn.microsoft.com/en-us/library/system.windows.forms.tablelayoutpanel.borderstyle(v=vs.110).aspx

装饰有:

[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]

因此 Intellisense 不会向您展示它,但它已记录在案并且可以正常工作.我不知道为什么它不可浏览.

So Intellisense won't show it to you, but it is documented and it works. I have no insight into why it is non-browsable.

这篇关于仅为 TableLayoutPanel 单元格绘制外边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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