为了账号安全,请及时绑定邮箱和手机立即绑定

使用ControlPaint.DrawBorder上色所有边框

使用ControlPaint.DrawBorder上色所有边框

C#
吃鸡游戏 2021-05-14 18:19:10
我试图通过Paint事件在Winform控件上做一些绘画,因为为什么不这样做。我已经将其连接起来了,因为StackOverlfow告诉我它可以工作:private void PaintLines(object sender, PaintEventArgs e){    ControlPaint.DrawBorder(e.Graphics, ClientRectangle,                    Color.Gray, 1, ButtonBorderStyle.Solid,                    Color.Gray, 1, ButtonBorderStyle.Solid,                    Color.Gray, 1, ButtonBorderStyle.Solid,                    Color.Gray, 1, ButtonBorderStyle.Solid);}问题是,仅适用于顶部和左侧边框,而不适用于右侧或底部边框。这是Designer.cs,因为我怀疑控件的设置方式存在问题。this.lblOffset.AutoSize = true;this.lblOffset.Dock = System.Windows.Forms.DockStyle.Fill;this.lblOffset.Location = new System.Drawing.Point(3, 25);this.lblOffset.Name = "lblOffset";this.lblOffset.Size = new System.Drawing.Size(114, 25);this.lblOffset.TabIndex = 1;this.lblOffset.Text = "Offset (V)";this.lblOffset.TextAlign = System.Drawing.ContentAlignment.MiddleRight;this.lblOffset.Paint += new System.Windows.Forms.PaintEventHandler(PaintLines);因此,问题是如何绘制四个边框?
查看完整描述

1 回答

?
慕哥9229398

TA贡献1877条经验 获得超6个赞

您使用的是不正确的ClientRectangle-整个表格之一。因此,该矩形的Width和Height值不适合Label的客户矩形。


使用Label的ClientRectangle,而不是:


ControlPaint.DrawBorder(e.Graphics, lblOffset.ClientRectangle,

    Color.Gray, 1, ButtonBorderStyle.Solid,

    Color.Gray, 1, ButtonBorderStyle.Solid,

    Color.Gray, 1, ButtonBorderStyle.Solid,

    Color.Gray, 1, ButtonBorderStyle.Solid);


查看完整回答
反对 回复 2021-05-23
  • 1 回答
  • 0 关注
  • 186 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信