0
這是我的源代碼。當我按下按鈕移動鼠標時,我似乎無法獲得位圖顯示面板上繪製的線條。沮喪和尋找某人來幫助我完成代碼,所以我可以完成我的9歲女兒的應用程序。預先感謝您...C#繪圖程序不會在屏幕上創建任何線條,因爲我試圖使用位圖繪製
namespace TV_PAINT
{
public partial class ALANA_PAINT : Form
{
Graphics g;
Pen p = new Pen(Color.Black, 7);
Point sp = new Point(0, 0);
Point ep = new Point(0, 0);
int m = 0;
Bitmap BP;
public ALANA_PAINT()
{
InitializeComponent();
tb1.Text = p.Width.ToString();
BP = new Bitmap(pnl1.ClientSize.Width, pnl1.ClientSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
}
private void closeButton_Click(object sender, EventArgs e)
{
pnl1.Dispose();
p.Dispose();
this.Close();
}
private void clearButton_Click(object sender, EventArgs e)
{
//pnl1.Invalidate();
p.Color = System.Drawing.Color.Black;
p.Width = 7;
tb1.Text = p.Width.ToString();
//pnl1.Invalidate();
}
private void pnl1_MouseDown(object sender, MouseEventArgs e)
{
sp = e.Location;
if (e.Button == MouseButtons.Left)
m = 1;
if (e.Button == MouseButtons.Right)
m = 1;
}
private void pnl1_MouseMove(object sender, MouseEventArgs e)
{
if (m == 1)
{
ep = e.Location;
//g = pnl1.CreateGraphics();
Graphics g = Graphics.FromImage(BP);
g.DrawLine(p, sp, ep);
}
sp = ep;
}
private void pnl1_MouseUp(object sender, MouseEventArgs e)
{
m = 0;
}
謝謝你的回答。我試圖製作一個繪圖程序,當它從屏幕移出或其他東西放在它的頂部時,它不會清除面板。所以我被告知實現一個位圖並繪製到位圖而不是面板。我的下一個目標是能夠將位圖保存到一個文件,如果她想保存她製作的圖片。希望這是有道理的... –
如果是這樣,我認爲你可以做這樣的事情http://stackoverflow.com/questions/26936109/how-do-i-save-a-winforms-panels-drawing-content-to -a-file –
好的,再次感謝你。我正在閱讀它... –