PictureBox的背景色问题
程序代码:using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitBackColor();
}
private void InitBackColor()
{
Graphics g = pictureBox1.CreateGraphics();
g.Clear(Color.Red);
}
private void button1_Click(object sender, EventArgs e)
{
InitBackColor();
}
}
}代码如上:我在Form里边放了一个PictureBox,并将它的BackColor设置Black。我希望在界面初始化的时候,能把颜色刷成红色。如上,同是调用InitBackColor()函数,构造函数中不能做,而Button1的点击事件却能实现把颜色刷成红色。搞不懂怎么实现在构造函数中能搞定?









我也想直接赋值呀,这里不只是颜色一项设置的,我还需要执行画图等动作的。只能这样呀,烦。。