使用控制台C#单击Plot按钮 [英] click button for Plot using console C#
问题描述
我使用控制台c#我没有使用Windows窗体应用程序在同一个图表上创建了两个图,一个没有单击按钮的图和另一个点击按钮,但点击按钮不起作用。
请帮忙,
谢谢
代码:
Hi,
I created a two plots at the same chart using console c# " I didn't use windows Form application " , one plot without click button and the other with click button but the click button doesn't work.
Please help,
Thank you
THE CODE :
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
namespace ConsoleApplication9
{
public partial class Form1 : Form
{
public Button button1;
public Chart chart1;
public Form1()
{
button1 = new Button();
button1.Text = "Click me";
this.Controls.Add(button1);
button1.Click += new EventHandler(button1_Click);
Chart chart1 = new Chart();
Series test1 = new Series();
Series test2 = new Series();
chart1.Series.Add("test1");
chart1.Series.Add("test2");
chart1.Series["test1"].ChartType = SeriesChartType.Spline;
chart1.Series["test1"].Color = Color.Red;
chart1.Series["test2"].ChartType = SeriesChartType.Spline;
this.Controls.Add(chart1);
ChartArea ChartArea0 = new ChartArea();
chart1.ChartAreas.Add(ChartArea0);
for (int i = 0; i < 50; i++)
{
int x1 = i;
double y1 = Math.Sin(x1);
double y = Math.Round(y1, 3);
chart1.Series["test1"].Points.AddXY
(x1, y);
}
chart1.Width = ClientRectangle.Width;
chart1.Height = ClientRectangle.Height;
}
protected override Size DefaultSize
{
get
{
return new Size(800, 500);
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 50; i++)
{
int x1 = i;
double y1 = Math.Sin(x1);
double y = Math.Round(y1, 3);
chart1.Series["test2"].Points.AddXY
(2 * x1, 2 * y);
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
}
```
推荐答案
点击按钮不起作用
好的..所以,我们需要改进这意味着什么
你(例如)在这条线上放一个断点
ok .. so, we need to refine what that means
have you (for instance) put a breakpoint on this line
for (int i = 0; i < 50; i++)
in你的button1_Click处理程序,看看当你点击按钮程序控件是否转移到处理程序?
(提示:转到VS编辑器中提到的那一行,推送'F9'/功能键9,它应该变成红色)
如果你运行你的程序(例如使用CTRL-F5)它会跳转到那一行,然后显然是你需要查看的图表代码
in your button1_Click handler, to see if when you click the button program control gets transferred to the handler ?
(hint : go to that mentioned line in the VS editor, push 'F9'/Function Key 9, it should go red)
if when you run your program (use CTRL-F5 for instance) and it does jump to that line, then clearly its the graphing code that you need to look at
这篇关于使用控制台C#单击Plot按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!