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 点个星星吧
|