winform 自定义控件_为TabelLayoutPanel添加一个边框颜色的属性
2018-09-19 17:32
211 查看
[code]using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace UserControl { public partial class TableLayoutPanelUserControl : TableLayoutPanel { public TableLayoutPanelUserControl() { // 控件风格 SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.UserPaint, true); //设置默认边框颜色为黑色 BorderColor = Color.Black; } #region 边框 /// <summary> /// 获取或设置按钮边框颜色 /// </summary> /// <value>The color of the focus.</value> [Browsable(true), DefaultValue(typeof(Color), "Black"), Description("按钮边框颜色")] [Category("Appearance")] public Color BorderColor { get; set; } #endregion //Table边框的绘制需要对每一个单元格的边框进行绘制 protected override void OnCellPaint(TableLayoutCellPaintEventArgs e) { base.OnCellPaint(e); var panel = this as TableLayoutPanel; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; var rectangle = e.CellBounds; using (Pen pen = new Pen(BorderColor)) { pen.Alignment = PenAlignment.Center; pen.DashStyle = DashStyle.Solid; if (e.Row == (panel.RowCount - 1)) { rectangle.Height -= 1; } if (e.Column == (panel.ColumnCount - 1)) { rectangle.Width -= 1; } e.Graphics.DrawRectangle(pen, rectangle); } } } }
阅读更多
相关文章推荐
- WinForm中修改panel边框的颜色等属性
- C# WinForm窗体控件Panel修改边框颜色以及边框宽度方法
- 为类目(类别)添加属性,使用storyboard设置边框颜色
- 在html里给button添加边框属性(颜色、线形状 )
- c#创建自定义控件在winform上添加该控件属性为空白
- C# WinForm修改Panel边框颜色
- Flex中如何利用titleIcon属性给Panel容器标题部添加一个ICON图标的例子
- 为类目(类别)添加属性,使用storyboard设置边框颜色
- Flex利用titleIcon属性给Panel容器标题部添加一个ICON图标
- C# WinForm修改Panel边框颜色
- 为类目(类别)添加属性,使用storyboard设置边框颜色(转载)
- POI操作Excel表格系列3 --- 背景颜色、边框等属性的读取和设置以及数据有效性的添加
- 一个表格说明RelativeLayout中的几个重要属性【Written By KillerLegend】
- jquery 给一个div添加边框 点及其他div前一个移除
- Panel设置透明属性 C#中颜色的使用
- 自定义控件添加上自定义的控件属性。
- Qt 5.8下自定义控件属性栏属性自我添加
- winform c# groupBox 的边框颜色
- 通过CSS禁止Chrome自动为输入框添加橘黄色边框,修改/禁止 chrome input边框颜色,
- 自定义控件如何给特殊类型的属性添加默认值 z