我有这样的用户控制代码的用户控制是图形图表:如何将form1变量传递给用户控件类?
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的应用程序时,出现错误。
可否请您展现不工作语法? – Fendy 2013-03-14 02:24:59
Fendy一旦我在用户控件代码中添加了form1和f1,错误就出现了。没有没有工作的语法。这只是需要我将Form1传递给GraphChart,但我无法做到。 – user2065612 2013-03-14 02:30:11
什么是您的Form1使用的命名空间 – 2013-03-14 02:43:08