所以我只是在尝试绘制图像和其他东西,但是我的代码似乎只在加载表单事件中有效?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Interface_Editing_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//This works perfectly
/*Image i = Image.FromFile(@"C:\Users\Simon\Pictures\clickedbutton.jpg");
Bitmap b = (Bitmap)panel1.BackgroundImage;
using (Graphics g = Graphics.FromImage(b))
{
g.DrawImage(i, 0, 0, i.Size.Width, i.Size.Height);
}*/
}
private void panel1_Click(object sender, EventArgs e)
{
//Doesnt draw anything, but will show the message box
Image i = Image.FromFile(@"C:\Users\Simon\Pictures\clickedbutton.jpg");
Bitmap b = (Bitmap)panel1.BackgroundImage;
using (Graphics g = Graphics.FromImage(b))
{
//MessageBox.Show(" ");
g.DrawImage(i, 0, 0, i.Size.Width, i.Size.Height);
}
}
}
}
我知道这很可能是我忽略的一些简单的事情,但如果有人能给我一些关于正在发生的事情的见解,我将不胜感激。谢谢