gpt4 book ai didi

c# - 面板中的图形故障

转载 作者:太空宇宙 更新时间:2023-11-03 11:21:47 24 4
gpt4 key购买 nike

我正在尝试将基本形状绘制到我表单的面板上。到目前为止没有任何反应,我不知道为什么。在我的表单的构造函数中调用此方法。

private void doGraphics()
{
Pen p = new Pen(Color.Black);//draws wire frame Shapes
SolidBrush sb = new SolidBrush(Color.Yellow);//draws filled Shapes
Graphics g = panel1.CreateGraphics();


Point[] pointArray = { new Point(100, 20), new Point(100, 0), new Point(120, 0), new Point(120, 20) };
g.FillPolygon(sb, pointArray);
g.DrawPolygon(p, pointArray);
}

任何建议都会很棒!

最佳答案

需要注册面板的Paint事件,使用自带参数的图形对象:

在构造函数中:

panel1.Paint += new PaintEventHandler(panel1_Paint);

处理程序本身:

void panel1_Paint(object sender, PaintEventArgs e) {
{
Pen p = new Pen(Color.Black);//draws wire frame Shapes
SolidBrush sb = new SolidBrush(Color.Yellow);//draws filled Shapes
Graphics g = e.Graphics; // From Arguments


Point[] pointArray = { new Point(100, 20), new Point(100, 0), new Point(120, 0), new Point(120, 20) };
g.FillPolygon(sb, pointArray);
g.DrawPolygon(p, pointArray);
}

关于c# - 面板中的图形故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10714715/

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