各位高手有什么好见意?先谢了。
[此贴子已经被作者于2007-9-12 16:02:36编辑过]
谢谢你的答复。问题是不能在groupBox7中画图,如果是在Form1中定义graphics对象,那么是可以的。但是我想在groupBox7中画图。再帮我想想?怎么解决?谢谢!
public partial class Form1 : Form
{
PortControl MB = new PortControl();
Graphics g;
public Form1()
{
InitializeComponent();
}
private void groupBox7_Paint(object sender, PaintEventArgs e)
{
g = e.Graphics;
......
}
private void timer1_Tick(object sender, EventArgs e)
{
.......
g.DrawLine(new Pen(new SolidBrush(Color.Red), 1), 25,41,12,19);//报错:参数错误
.......
}
[此贴子已经被作者于2007-9-12 12:41:00编辑过]
按你的意思,程序应该是这样写吗?
public partial class Form1 : Form
{
Graphics g;
public Form1()
{
InitializeComponent();
}
private void groupBox7_Paint(object sender, PaintEventArgs e)
{
//g = GRAPHICS。FROMHANDLE(groupBox7.HANDLE);//内存不足
......
}
private void timer1_Tick(object sender, EventArgs e)
{
//g = GRAPHICS。FROMHANDLE(groupBox7.HANDLE);//内存不足
g.DrawLine(new Pen(new SolidBrush(Color.Red), 1), 25,41,12,19);
g。DISPOSE();)
.......
}
[此贴子已经被作者于2007-9-12 16:34:30编辑过]
注意大小写,什么意思?我这里只是表示一下,其实我是这样写的:
public partial class Form1 : Form
{
Graphics g;
public Form1()
{
InitializeComponent();
}
private void groupBox7_Paint(object sender, PaintEventArgs e)
{
//g = Graphics.Graphics.FromHdc(groupBox7.Handle );;//内存不足
......
}
private void timer1_Tick(object sender, EventArgs e)
{
//g = Graphics.Graphics.FromHdc(groupBox7.HANDLE);//内存不足
g.DrawLine(new Pen(new SolidBrush(Color.Red), 1), 25,41,12,19);
g.Dispose();
}