通常的方法都是使用textbox等控件,那么如何才能不使用控件直接把字符串写到窗体上呢?
使用 窗体的paint函数,和Graphics类就可以实现
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Font fnt = new Font(Label1.Font.Name, 12, FontStyle.Bold);
StringFormat sf = new StringFormat();
string s = "asjflafjla";
g.DrawString(s, fnt, Brushes.Black, 100F, 10F, sf);
}
另外,使用 this.Invalidate();可以更新窗体。