额,我刚学c#不久额,问下哈
现在有这么个类drawbackground的draw方法用来画15x15的格子,然后我要在form1的paint事件里调用这个方法。
从未对字段“123.drawbackground.g”赋值,字段将一直保持其默认值 null。报这个错额。最好能回答问题的说后多说一下Graphics g这个东西,个人感觉不是很理解.
class drawbackground
{
private static Graphics g;
private static Pen p = new Pen(Color.Black);//定一个黑色画笔
public static void draw()
{ for (int x = 0; x < 15; x++)
{
for (int y = 0; y < 15; y++)
{
g.DrawLine(p,x, y * 40, 600, y *40);//横线
g.DrawLine(p, x * 40, y, x * 40, 600);//竖线 }
}
}
}form1里调用的 private void Form1_Paint(object sender, PaintEventArgs e)
{
drawbackground.draw();
}
现在有这么个类drawbackground的draw方法用来画15x15的格子,然后我要在form1的paint事件里调用这个方法。
从未对字段“123.drawbackground.g”赋值,字段将一直保持其默认值 null。报这个错额。最好能回答问题的说后多说一下Graphics g这个东西,个人感觉不是很理解.
class drawbackground
{
private static Graphics g;
private static Pen p = new Pen(Color.Black);//定一个黑色画笔
public static void draw()
{ for (int x = 0; x < 15; x++)
{
for (int y = 0; y < 15; y++)
{
g.DrawLine(p,x, y * 40, 600, y *40);//横线
g.DrawLine(p, x * 40, y, x * 40, 600);//竖线 }
}
}
}form1里调用的 private void Form1_Paint(object sender, PaintEventArgs e)
{
drawbackground.draw();
}
解决方案 »
- N年没解决的数据提交问题,100求解
- C#多个数据库如何设计?
- 编写手机网页下载文件问题????
- C#用户注册代码?
- 找遍了CSDN,用百度搜索也没有找到答案——UP有分
- C#中,程序如何保证公网上的多台服务器间的数据同步
- 图像显示路径问题?超难问题,请高手指点
- 关于在.net Remoting的事件问题
- 关于在数据库中存储和读取图片(Access)
- VC中的ON_UPDATE_COMMAND_UI在C#中如何实现?
- 关于private ManualResetEvent m_eventSend = new ManualResetEvent(false)
- N多客户端,它们的信息怎么传递到服务器上
class drawbackground
{
private Graphics g;
private Pen p = new Pen(Color.Black);//定一个黑色画笔 public drawbackground(Graphics graphics)
{
g = graphics;
} public void draw()
{
for (int x = 0; x < 15; x++)
{
for (int y = 0; y < 15; y++)
{
g.DrawLine(p, x, y * 40, 600, y * 40);//横线
g.DrawLine(p, x * 40, y, x * 40, 600);//竖线 }
}
}
} private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
drawbackground dbg = new drawbackground(g);
dbg.draw();
}