gpt4 book ai didi

c# - OnPaint 在调整大小时留下痕迹

转载 作者:行者123 更新时间:2023-11-30 13:48:46 25 4
gpt4 key购买 nike

我正在创建一个带有自定义边框的表单。我想使用 onPaint 重写来绘制自己的边框。不幸的是,当我只使用下面的代码时,我得到了图像的踪迹。

有人知道怎么解决吗?是的,我已将 DoubleBuffered 设置为 true。

protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;

// Background
g.FillRectangle(new SolidBrush(ColorTranslator.FromHtml("#EFEFF7")), new Rectangle(0, 0, this.Width - 1, this.Height - 1));

// Outer Borders
g.DrawImage(Resources.Resource.OuterBorderTopLeft, new Rectangle(0, 0, 13, 13));
g.DrawImage(Resources.Resource.OuterBorderTopLeft1, new Rectangle(13, 0, 221, 13));
g.DrawImage(Resources.Resource.OuterBorderTopLeft2, new Rectangle(0, 13, 13, 221));
g.DrawImage(Resources.Resource.OuterBorderTopRight, new Rectangle(this.Size.Width - 13, 0, 13, 13));
g.DrawImage(Resources.Resource.OuterBorderTopRight1, new Rectangle(this.Size.Width - 13, 13, 13, 221));
g.DrawImage(Resources.Resource.OuterBorderTopRight2, new Rectangle(this.Size.Width - 234, 0, 221, 13));
g.DrawImage(Resources.Resource.OuterBorderBottomLeft, new Rectangle(0, this.Size.Height - 13, 13, 13));
g.DrawImage(Resources.Resource.OuterBorderBottomLeft1, new Rectangle(0, this.Size.Height - 234, 13, 221));
g.DrawImage(Resources.Resource.OuterBorderBottomLeft2, new Rectangle(13, this.Size.Height - 13, 221, 13));
g.DrawImage(Resources.Resource.OuterBorderBottomRight, new Rectangle(this.Size.Width - 13, this.Size.Height - 13, 13, 13));
g.DrawImage(Resources.Resource.OuterBorderBottomRight1, new Rectangle(this.Size.Width - 234, this.Size.Height - 13, 221, 13));
g.DrawImage(Resources.Resource.OuterBorderBottomRight2, new Rectangle(this.Size.Width - 13, this.Size.Height - 234, 13, 221));
base.OnPaint(e);
}

最佳答案

也尝试重写 resize 方法:

protected override void OnResize(EventArgs e) {
base.OnResize(e);
this.Invalidate();
}

或者在构造函数中,您可以添加另一个设置:

public Form1() {
InitializeComponent();
this.DoubleBuffered = true;
this.ResizeRedraw = true;
}

关于c# - OnPaint 在调整大小时留下痕迹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11532214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com