public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Bitmap b = new Bitmap(@"F:\face.jpeg");
Graphics g = this.CreateGraphics();
g.DrawImage(b, 20, 30);
}
}
图片未加载表单。 这是什么原因?而且,我该怎么做?
答案 0 :(得分:2)
因为它不是在WinForms中绘制的正确方法。将您的绘图代码移动到OnPaint()
方法,如下所示:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage(bmp, 20, 30);
}
当然可以提前加载位图。
答案 1 :(得分:1)