我是 C# 的初學者;我使用等于面板大小的位圖并將其設置為面板的背景圖像。我也想setpixel在單擊事件時使用面板更新來更新位圖。但是當我點擊面板時它不起作用。這是我的代碼:public partial class Form1 : Form { Bitmap bmp; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { bmp = new Bitmap(panel1.Width, panel1.Height); panel1.BackgroundImage = (Image)bmp; panel1.BackgroundImageLayout = ImageLayout.None; } private void panel1_MouseClick(object sender, MouseEventArgs e) { label1.Text = (e.Location.X).ToString(); bmp.SetPixel(e.Location.X, e.Location.Y, Color.White); bmp.SetPixel((e.Location.X)+1, e.Location.Y, Color.White); bmp.SetPixel((e.Location.X)-1, e.Location.Y, Color.White); bmp.SetPixel(e.Location.X, (e.Location.Y)+1, Color.White); bmp.SetPixel(e.Location.X, (e.Location.Y)-1, Color.White); } }
- 1 回答
- 0 關注
- 257 瀏覽
添加回答
舉報
0/150
提交
取消