目的:点一个按钮,子窗口嵌在主窗口(panel)上,在主窗口选完combobox的值后,按查询按钮,子窗口根据combobox的值选择数据使chart出图,然后改变combobox的值,子窗口上chart所连接的数据发生改变,图发生改变
问题:不管我怎么选combobox的值,它都只传comboBox1.Text=CHR1,comboBox2.Text=1,comboBox3.Text=1009;都只连接同一组数。
我该怎么使窗体间传combobox当前选中的值
主窗口中部分程序
public partial class Form1 : Form
{
Win1 w1;
Win2 w2;
Win3 w3;
Win4 w4;
Win5 w5;
private bool flag1;
private bool flag2;
private bool flag;
public string com1
{
get { return comboBox1.Text; }
}
public string com2
{
get { return comboBox2.Text; }
}
public string com3
{
get { return comboBox3.Text; }
}
public Form1()
{
InitializeComponent();
string[] chexing = new[] { "CHR1", "CHR2", "CHR3" };
string[] tuoche = new[] { "1", "2", "3" };
string[] cgqxh = new[] { "1009", "1002", "1666" };
comboBox1.DataSource = chexing;
comboBox1.Name = "comboBox1";
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox2.DataSource = tuoche;
comboBox2.Name = "comboBox2";
comboBox2.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox3.DataSource = cgqxh;
comboBox3.Name = "comboBox3";
comboBox3.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox3.Enabled = false;
if (flag1 == true && flag2 == true)//按完combox1和combox2之后,才能选combox3
{
comboBox3.Enabled = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
w1 = new Win1();
w2 = new Win2();
w3 = new Win3();
w4 = new Win4();
w5 = new Win5();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
this.panel1.Controls.Clear(); // 清空原有的控件
w1.TopLevel = false; // 非顶级窗口
w1.FormBorderStyle = FormBorderStyle.None; // 不显示标题栏
w1.WindowState = FormWindowState.Maximized;
this.panel1.Controls.Add(w1); // 添加w1窗体
w1.Show();
flag = true;
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
flag1 = true;
}
private void comboBox2_SelectedValueChanged(object sender, EventArgs e)
{
flag2 = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (flag == true && flag1 == true && flag2 == true)
{
w1.Creatchart1();
}
}
子窗口中部分程序
public partial class Win1 : Form
{
private string a;
private string b;
private string c;
private SQLiteConnection m;
public Win1()
{
InitializeComponent();
}
public void Creatchart1()
{
chart1.Series.Clear();
Form1 f1 = new Form1();
a = f1.com1.ToString();
b = f1.com2.ToString();
c = f1.com3.ToString();
string wax = a + b + c;
string dbPath = @"D:\历年高考分数.db";
string sq = @"Data Source=" + dbPath;
m = new SQLiteConnection(sq);
m.Open();
SQLiteDataAdapter mAdapter = new SQLiteDataAdapter("select " + wax + ",yxlc from 表2", m);
DataSet ds = new DataSet();
mAdapter.Fill(ds);
DataTable dt = ds.Tables[0];
//设置图表的数据源
Series Series1 = new Series();
chart1.DataSource = dt;
Series1.IsValueShownAsLabel = false;//是否显示图例
chart1.Series.Add(Series1);
chart1.Series["Series1"].ChartType = SeriesChartType.Spline;//形状
chart1.Series[0].XValueMember = "yxlc";//X轴数据成员列
chart1.Series[0].YValueMembers = wax;
chart1.Series[0].IsValueShownAsLabel = true;//显示坐标
chart1.ChartAreas[0].AxisX.Title = "运行里程(万公里)";
chart1.ChartAreas[0].AxisY.Title = "故障率(%)";
chart1.Series[0].MarkerStyle = MarkerStyle.Circle;
要提//需示的信息
chart1.Series[0].ToolTip = "运行里程:#VALX\\n故障率:#VALY";
//将文字移到外侧
chart1.Series[0]["PieLabelStyle"] = "Outside";
chart1.DataBind();
chart1.BringToFront();
m.Close();
}