如何在表格上画一个覆盖整个工作区域的圆?
如何在表格上画一个覆盖整个工作区域的圆?
我已经尝试过以下代码。但是当我重新调整表格大小时,圆圈会变形。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
Pen redPen = new Pen(Color.Red, 3);
Rectangle rect = new Rectangle(0,0, this.ClientSize.Width, this.ClientSize.Height);
g.DrawEllipse(redPen, rect);
}
}
How to draw a circle on a form that covers the whole working area?
I have tried the following code. But when I re-size the form, the circle is distorted.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
Pen redPen = new Pen(Color.Red, 3);
Rectangle rect = new Rectangle(0,0, this.ClientSize.Width, this.ClientSize.Height);
g.DrawEllipse(redPen, rect);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还应该挂钩 ClientSizeChanged 事件来触发重绘。
当前发生的情况是,Windows 假定只有变得可见的一小部分需要重新绘制,并剪掉其他所有内容。因此,在调整大小时,您需要使完整表单无效 (
Invalidate()
)。如果调整大小时圆圈开始闪烁,请启用表单的双缓冲。
You should hook into the ClientSizeChanged event as well to trigger a redraw.
What currently happens is that Windows assumes that only the small portion which became visible needs to be redrawn, and clips everything else off. You therefore need to invalidate the full form (
Invalidate()
) when a resize takes place.If the circle starts flickering when resizing, enable double buffering of the form.
尝试将 Form 的 DoubleBuffered 属性设置为 true。
Try to set the DoubleBuffered property of the Form to true.