C#在文本框输入文字,单击按钮,在picturebox图片上显示,在文本框重新输入文字,图片上文字被新的代替

下面这个怎么改

private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
Graphics myg = pictureBox1.CreateGraphics();
SolidBrush mybrush = new SolidBrush(Color.Red);
Font myfont = new Font("黑体", 20);
myg.DrawString(textBox1 .Text , myfont, mybrush, new Rectangle(120, 5, 280, 120));
}
else
{
MessageBox.Show(this, "wenzi", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

private void button2_Click(object sender, EventArgs e)
{
    if (textBox1.Text != "")
    {
        Graphics myg = pictureBox1.CreateGraphics();
        gp.Clear(pictureBox1.BackColor);//加一句这个
        SolidBrush mybrush = new SolidBrush(Color.Red);
        Font myfont = new Font("黑体", 20);
        myg.DrawString(textBox1 .Text , myfont, mybrush, new Rectangle(120, 5, 280, 120));
    }
    else
    {
        MessageBox.Show(this, "wenzi", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-08-27
你重新输入的时候字体就会叠加是吧?追问

相似回答