日期:2014-05-17  浏览次数:20767 次

Picture Box 点击委托事件
请问点击PictureBox后为什么没有执行pictureBox1_Paint

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    string rdWords = GetRandomWords();
    Font font = new System.Drawing.Font("Consolas", 18, FontStyle.Bold);
    g.DrawString(rdWords, font, Brushes.Red, 5, 5);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
    PictureBox pb = new PictureBox();
    pb.Paint += new PaintEventHandler(pictureBox1_Paint);
}
PictureBox?委托

------解决方案--------------------
初始化窗口的时候
pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); 
private void pictureBox1_Click(object sender, EventArgs e)
{     
    pictureBox1.Refresh();