我正試圖通過單擊按鈕來製作一個程序,以在Panel
(正方形,圓形等)上繪製。通過單擊WinForms中的按鈕在面板上繪圖
到目前爲止,我還沒有做很多工作,只是試着直接將代碼繪製到面板上,但不知道如何將其移動到按鈕上。這是我迄今爲止的代碼。
如果你知道比我使用的更好的繪製方法,請告訴我。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void mainPanel_Paint(object sender, PaintEventArgs e)
{
Graphics g;
g = CreateGraphics();
Pen pen = new Pen(Color.Black);
Rectangle r = new Rectangle(10, 10, 100, 100);
g.DrawRectangle(pen, r);
}
private void circleButton_Click(object sender, EventArgs e)
{
}
private void drawButton_Click(object sender, EventArgs e)
{
}
}
}
初學者:This:'Graphics g; g = CreateGraphics();'應該是:'g = e.Graphics'!並繪製不同的東西,你需要收集列表這些東西,並繪製它們都在'Paint'事件..看到[這裏](http://stackoverflow.com/search?q=user%3A3152130+drawaction)我的幾篇文章討論瞭如何通過創建drawAction類來實現winforms中的圖形! ' –
TaW