このユーザー コントロール コードは、ユーザー コントロールが GraphChart です。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Windows.Forms.DataVisualization.Charting;
namespace GatherLinks
{
public partial class GraphChart : UserControl
{
Form1 form1;
public GraphChart(Form1 f1)
{
InitializeComponent();
form1 = f1;
}
private void GraphChart_Load(object sender, EventArgs e)
{
chart1.Series.Clear();
var series1 = new System.Windows.Forms.DataVisualization.Charting.Series
{
Name = "Series1",
Color = System.Drawing.Color.Green,
IsVisibleInLegend = false,
IsXValueIndexed = true,
ChartType = SeriesChartType.Line
};
this.chart1.Series.Add(series1);
//for (int i = 0; i < 100; i++)
//{
series1.Points.AddXY(form1.axisX, form1.axisY);
//}
chart1.Invalidate();
}
form1 および f1 変数を追加した後、エラーが発生します。
エラー 2 GatherLinks.GraphChart' には引数を 0 個取るコンストラクタが含まれていません
エラーをダブルクリックすると、Form1 デザイナー cs の次の行に移動します。
this.graphChart1 = new GatherLinks.GraphChart();
Form1 を () の間に入れようとしましたが、エラーが発生して機能しません。どうすれば解決できますか?
編集:
私はちょうどユーザーコントロールコードでやった:
public partial class GraphChart : UserControl
{
Form1 form1;
public GraphChart() { }
public GraphChart(Form1 f1)
{
InitializeComponent();
form1 = f1;
}
しかし、現在 Form1 コンストラクターには次の行があります。
this.graphChart1.chart1.MouseMove += chart1_MouseMove;
this.graphChart1.chart1.MouseLeave += chart1_MouseLeave;
彼らは問題なく動作しましたが、次の行を追加するとすぐに: public GraphChart() { } アプリケーションを実行すると、 chart1 が null であるというエラーが発生します。