您的位置:首页 > 其它

WinForm点击按钮在对应的panel里画图

2015-08-18 09:41 267 查看
  panel在form1里,button在form1上方,panel在下面。

  主要是在button1的click时间获取panel的画笔。

  下面的不行,在panel里获取画笔,然后传到button1,根本不行,因为程序的逻辑是,先点击button1加载数据,关键是怎么调用panel1_Paint方法,不知道如何调用,那就没办法同时获取panel的画笔,同理,因为此时在panel1化数据的话还没有点击button1加载数据,所以dataProject是null,而且图形根本出不来,加一个判断就ok了。

private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (dataProject != null)
{
CreateGantt(g, dataProject);
}
}


==============================================================

  下面就ok。

private void button1_Click(object sender, EventArgs e)
{
////string path = Directory.GetCurrentDirectory();
String json = ReadJSON("E:\\VS-work\\Gantt\\Gantt\\project.txt");
dataProject = (Hashtable)Test.JSON.Decode(json);
Graphics g = this.panel1.CreateGraphics();
CreateGantt(g, dataProject);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: