这是我的代码:
Button b = new Button();
Graphics g = b.CreateGraphics();
g.DrawString("Hello World", new Font(FontFamily.GenericSerif, 5), Brushes.Red, new PointF(1, 1));
b.Height = 100;
b.Width = 100;
this.Controls.Add(b);
我得到一个按钮,但上面没有图像..
我正在使用以下代码,它可以满足我的需要。感谢大家。
Button b = new Button();
b.Height = 100;
b.Width = 100;
Bitmap bitmap = new Bitmap(b.Height, b.Width);
Graphics g = Graphics.FromImage(bitmap);
g.DrawString("Hello World", new Font(FontFamily.GenericSerif, 5), Brushes.Red, new PointF(1, 1));
b.Image = bitmap;
this.Controls.Add(b);