当tableLayoutPanel列单元格或行单元格合并后中间的线条如何才能去除掉了
急 在线等!!!
急 在线等!!!
解决方案 »
- 请教下如果有一个未知的由0—9组成的7位数,怎么可以快速的判断出是什么数呢?
- 用UML,或Csharp语言描述
- TextBox和RichTextBox无法输入中文、无法读取中文
- 一个winform窗体上有十几个textbox,每个textbox是绑定在一个datatable的不同字段上的,如何快速简单判断是否修改了textbox的值。
- 简单问题,请问这个xml XPath 寻找路径怎么写??内有xml的具体表示文档。
- XPathNavigator的简单问题,在线等!!!
- 请教一个获取窗体变量集合的问题?
- 字符串要怎么转才能怎么支持XPATH语法
- 帮帮忙,有人回答这个问题吗
- 请问,编写B/S结构用asp.net,还是用c#?
- 菜鸟提问,请问如何将二给数组绑定到DataGridView
- 求一个泛型方法的实现
tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;(如果一定要边框)然后在相应CellPaint中自己画合并后的边框,可以充分用参数中的Row,Column以及CellBounds信息。
若要在单元格中对齐控件,或在单元格内拉伸控件,请使用控件的 Anchor 属性。有关更多信息,请参见演练:使用 TableLayoutPanel 在 Windows 窗体上排列控件。
显示的对话框和菜单命令可能会与“帮助”中的描述不同,具体取决于您现用的设置或版本。若要更改设置,请在“工具”菜单上选择“导入和导出设置”。有关更多信息,请参见 Visual Studio 设置。
{
Pen borderPen;
public Pen BorderPen { get { return this.borderPen; } set { this.borderPen = value; } } protected override void OnCreateControl()
{
base.OnCreateControl(); this.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;
this.borderPen = this.borderPen == null ? Pens.DarkGray : this.borderPen;
this.ControlAdded += delegate { this.cellBorders = null; };
this.ControlRemoved += delegate { this.cellBorders = null; };
} protected override void OnCellPaint(TableLayoutCellPaintEventArgs e)
{
base.OnCellPaint(e); Pen pen = this.BorderPen;
Borders borders = this[e.Row, e.Column];
Point topleft = new Point(e.CellBounds.Left, e.CellBounds.Top);
Point topright = new Point(e.CellBounds.Right - 1, e.CellBounds.Top);
Point bottomleft = new Point(e.CellBounds.Left, e.CellBounds.Bottom - 1);
Point bottomright = new Point(e.CellBounds.Right - 1, e.CellBounds.Bottom - 1); if ((borders & Borders.Left) == Borders.Left) e.Graphics.DrawLine(pen, topleft, bottomleft);
if ((borders & Borders.Right) == Borders.Right) e.Graphics.DrawLine(pen, topright, bottomright);
if ((borders & Borders.Top) == Borders.Top) e.Graphics.DrawLine(pen, topleft, topright);
if ((borders & Borders.Bottom) == Borders.Bottom) e.Graphics.DrawLine(pen, bottomleft, bottomright);
} [Flags]
enum Borders
{
None = 0, Left = 1, Right = 2, Top = 4, Bottom = 8,
} Borders[,] cellBorders;
Borders this[int row, int col]
{
get
{
if (this.cellBorders == null)
{
PrepareCellBorders();
}
if (row < this.cellBorders.GetLength(0) && col < this.cellBorders.GetLength(1))
{
return this.cellBorders[row, col];
}
return Borders.None;
}
set
{
if (this.cellBorders == null)
{
PrepareCellBorders();
}
if (row < this.cellBorders.GetLength(0) && col < this.cellBorders.GetLength(1))
{
this.cellBorders[row, col] = value;
}
}
} private void PrepareCellBorders()
{
this.cellBorders = new Borders[this.RowCount, this.ColumnCount];
for (int y = 0; y < cellBorders.GetLength(0); y++)
{
for (int x = 0; x < cellBorders.GetLength(1); x++)
{
cellBorders[y, x] = Borders.Top | Borders.Left;
if (y == cellBorders.GetLength(0) - 1) cellBorders[y, x] |= Borders.Bottom;
if (x == cellBorders.GetLength(1) - 1) cellBorders[y, x] |= Borders.Right;
}
} foreach (Control c in this.Controls)
{
int rowspan = this.GetRowSpan(c);
int colspan = this.GetColumnSpan(c);
TableLayoutPanelCellPosition pos = this.GetCellPosition(c); for (int y = 0; y < rowspan; y++)
{
for (int x = 0; x < colspan; x++)
{
if (y > 0) this[pos.Row + y, pos.Column + x] &= ~Borders.Top;
if (x > 0) this[pos.Row + y, pos.Column + x] &= ~Borders.Left;
}
}
}
}}