请问如何改变C#的winform的panel的指定区域的背景颜色
private void button1_Click(object sender, EventArgs e)
{
Graphics g = panel1.CreateGraphics();
Point p1 = new Point(int.Parse(textBox1.Text),int.Parse(textBox5.Text));
Point p2 = new Point(int.Parse(textBox2.Text), int.Parse(textBox6.Text));
Point p3 = new Point(int.Parse(textBox3.Text), int.Parse(textBox7.Text));
Point p4 = new Point(int.Parse(textBox4.Text), int.Parse(textBox8.Text));
Point[] ps = new Point[4] { p1, p2, p3, p4 };
Brush b = Brushes.Red;
g.FillClosedCurve(b,ps);//可以换其他的东西来改变效果
}
不过form里的透明都是"假透明"
{
Graphics gp = panel1.CreateGraphics();
Rectangle rect = new Rectangle(new Point(1, 1), new Size(100, 50));
//gp.DrawRectangle(new Pen(Brushes.Red, 5f), rect); //线
gp.FillRectangle(Brushes.Red, rect); //填充
gp.Flush();
}
测试通过。