只是C#創建一個新的Windows窗體應用程序,並嘗試這個代碼並不如期望的工作:如何在加載時動態設置表單的背景圖片?
private void Form1_Load(object sender, EventArgs e)
{
Bitmap rBitmap = new Bitmap(600, 500);
Graphics graphics = Graphics.FromImage(rBitmap);
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, 600, 500), Color.DeepSkyBlue, Color.Green, LinearGradientMode.Vertical);
brush.SetSigmaBellShape(0.0f, 1f);
graphics.FillRectangle(brush, new Rectangle(0, 0, 600, 500));
Form1.ActiveForm.BackgroundImage = rBitmap;
}
的形式加載使用默認值。如果向表單添加按鈕並添加相同的代碼,則可以根據需要設置表單的背景圖像。那麼如何在Form1_Load事件中動態實現這一功能,以便在程序打開時顯示圖像?
搜索:
'this.BackgroundImage = rBitmap; '? – Eser