如何绘制形状,窗户的模板? [英] How to draw shapes in panels of windows form?
问题描述
我使用面板绘制形状像圆,但问题是,当我更改选项卡或最小化程序和放大器;然后最大化该程序,然后取出绘制每一件事情。任何一个可以告诉我是什么原因?
I am using panel to draw shapes like circle, but the problem is that when I change tab or minimize the program & then maximize the program, then every thing drawn removed. Can any one tell me what's the reason?
推荐答案
既然你没有张贴任何代码,你走你所有的读者猜测。我的猜测是,你是最有可能使用的createGraphics,这可能是一个错误。
Since you didn't post any code, you leave all of your readers guessing. My guess is that you are most likely using CreateGraphics, which is probably a mistake.
您面板的Paint事件应该是这个样子:
Your panel's paint event should look something like this:
private void panel1_Paint(object sender, PaintEventArgs e) {
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.FillEllipse(Brushes.Red, new Rectangle(10, 10, 32, 32));
}
您完成所有的绘图Paint事件。要强制刷新,只需调用 panel1.Invalidate()
。
You do all of your drawing in the paint event. To force a refresh, just call panel1.Invalidate()
.
如果绘制成位图,你可以处理它是这样的:
If drawing to a bitmap, you could handle it like this:
Bitmap bmp = new Bitmap(500, 500);
private void button1_Click(object sender, EventArgs e) {
using (Graphics g = Graphics.FromImage(bmp)) {
g.SmoothingMode = SmoothingMode.AntiAlias;
g.Clear(Color.White);
g.FillEllipse(Brushes.Red, new Rectangle(10, 10, 32, 32));
}
panel1.Invalidate();
}
private void panel1_Paint(object sender, PaintEventArgs e) {
e.Graphics.DrawImage(bmp, new Point(0, 0));
}
这篇关于如何绘制形状,窗户的模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!