设为首页 加入收藏

TOP

(八十)c#Winform自定义控件-分割线标签(三)
2019-10-09 20:05:59 】 浏览:361
Tags:八十 c#Winform 定义 控件 -分割线 标签
eight);
165 this.Width = _width; 166 } 167 } 168 /// <summary> 169 /// Initializes a new instance of the <see cref="UCSplitLabel"/> class. 170 /// </summary> 171 public UCSplitLabel() 172 : base() 173 { 174 if (ControlHelper.IsDesignMode()) 175 { 176 Text = "分割线"; 177 Font = new Font("微软雅黑", 8f); 178 } 179 this.AutoSize = false; 180 Padding = new Padding(20, 0, 0, 0); 181 MinimumSize = new System.Drawing.Size(150, 10); 182 PaddingChanged += UCSplitLabel_PaddingChanged; 183 this.Width = 200; 184 } 185 186 /// <summary> 187 /// Handles the PaddingChanged event of the UCSplitLabel control. 188 /// </summary> 189 /// <param name="sender">The source of the event.</param> 190 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> 191 void UCSplitLabel_PaddingChanged(object sender, EventArgs e) 192 { 193 if (Padding.Left < 20) 194 { 195 Padding = new Padding(20, Padding.Top, Padding.Right, Padding.Bottom); 196 } 197 } 198 199 /// <summary> 200 /// Handles the <see cref="E:Paint" /> event. 201 /// </summary> 202 /// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" /></param> 203 protected override void OnPaint(PaintEventArgs e) 204 { 205 base.OnPaint(e); 206 var g = e.Graphics; 207 g.SetGDIHigh(); 208 209 var size = g.MeasureString(Text, Font); 210 g.DrawLine(new Pen(new SolidBrush(lineColor)), new PointF(1, Padding.Top + (this.Height - Padding.Top - Padding.Bottom) / 2), new PointF(Padding.Left - 2, Padding.Top + (this.Height - Padding.Top - Padding.Bottom) / 2)); 211 g.DrawLine(new Pen(new SolidBrush(lineColor)), new PointF(Padding.Left + size.Width + 1, Padding.Top + (this.Height - Padding.Top - Padding.Bottom) / 2), new PointF(Width - Padding.Right, Padding.Top + (this.Height - Padding.Top - Padding.Bottom) / 2)); 212 213 } 214 } 215 }

 

最后的话

如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇dotnetcore+vue+elementUI 前后端.. 下一篇Parallel.ForEach 使用多线遍历循..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目