简体   繁体   English

ZedGraph:在按钮单击事件下不起作用

[英]ZedGraph: Won't work under button click event

I a windows forms project in VS2012 with a ZedGraph Control and a button. 我在VS2012中使用ZedGraph控件和按钮的Windows窗体项目。 I have the following code: 我有以下代码:

double[] testing = { 0, 1, 2, 3, 4, 5 };
LineItem myline = zedGraphControl1.GraphPane.AddCurve("testing", testing, testing, Color.Red);
zedGraphControl1.AxisChange();

When I have it under the Form_load event, the line chart is generated like it should be. 当我在Form_load事件下拥有它时,将生成折线图,就像应该的那样。 However if I move the code under the button click event, nothing happens. 但是,如果我将代码移动到按钮单击事件下,则什么也不会发生。 I just have a blank graph. 我只有一个空白图表。

I've made sure the event is firing and when I look under the GraphPane.CurveList there is a curve with the expected values. 我确保事件正在触发,当我在GraphPane.CurveList下查看时,会有一条带有期望值的曲线。

Can anyone suggest a reason why this might be happening? 谁能说出发生这种情况的原因?

Maybe I have a solution for your problem. 也许我有解决您问题的方法。 I have tried to solve it and the solution was very simple. 我试图解决它,解决方案非常简单。 At the end of your code try to add : 在代码末尾尝试添加:

double[] testing = { 0, 1, 2, 3, 4, 5 };
LineItem myline = zedGraphControl1.GraphPane.AddCurve("testing", testing, testing, Color.Red);
zedGraphControl1.AxisChange();

ZedGraphControl1.Refresh()

But this will make changes after button clicking. 但这将在单击按钮后进行更改。 For styling you have to write your code in Form_Load or in another sub. 对于样式,您必须在Form_Load或其他子代码中编写代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM