我想在单击按钮时添加ZedGraph,但单击按钮时ZedGraph不会出现。这是我的按钮点击处理程序:
ZedGraphControl zg1 = new ZedGraphControl();
zg1.Dock = DockStyle.Fill;
GraphPane myPane = new GraphPane();
BarItem myBar = new BarItem("Bar1");
myBar.AddPoint(1, 10);
myBar.AddPoint(2, 20);
myBar.Bar.Fill = new Fill(Color.AliceBlue, Color.White, Color.AliceBlue);
zg1.AxisChange();
zg1.Invalidate();
zg1.Show();
答案 0 :(得分:2)
向我突出的主要事情是,我没有看到你adding your new Control
到你的容器对象,而是Form
或Panel
。您也没有将Pane
或Bar
与ZedGraphControl
尝试类似这样的事情
ZedGraphControl zg1 = new ZedGraphControl();
zg1.Dock = DockStyle.Fill;
zg1.GraphPane = new GraphPane();
BarItem myBar = new BarItem("Bar1");
myBar.AddPoint(1, 10);
myBar.AddPoint(2, 20);
myBar.Bar.Fill = new Fill(Color.AliceBlue, Color.White, Color.AliceBlue);
zg1.GraphPane.CurveList.Add(myBar);
zg1.AxisChange();
zg1.Invalidate();
zg1.Show();
this.Controls.Add(zg1);