日期:2014-05-19  浏览次数:20846 次

弱弱的问一下,如何在form上画一个圆!!!
或者画个点,画条线什么的,小弟不晓得该从哪里下手!!!

------解决方案--------------------
GDI+,去官网上看看
------解决方案--------------------
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);


private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Red, 0, 0, 200, 200);
}
------解决方案--------------------
private void button1_Click(object sender, EventArgs e)
{
using (Graphics g = this.CreateGraphics())
{
g.DrawEllipse(Pens.Red,0, 0, 200, 200);
}
}
但这个圆在窗体最小化或移动后是不会重画的 最好的办法是把圆的信息保存另外的变量 在Paint事件里生画
------解决方案--------------------
mark~~~~
------解决方案--------------------
Bitmap formImage;

public Form1()
{
InitializeComponent();
formImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
}

private void button1_Click(object sender, EventArgs e)
{
using (Graphics g = Graphics.FromImage(formImage))
{
g.DrawEllipse(Pens.Red, 0, 0, 200, 200);
this.Invalidate(ClientRectangle);
}
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(formImage, 0, 0);
}