主窗口为Form1,子窗口为w1
Form1下程序
Win1 w1; w1 = new Win1();
private void toolStripButton1_Click(object sender, EventArgs e)
{
this.panel1.Controls.Clear(); // 清空原有的控件
w1.TopLevel = false; // 非顶级窗口
w1.FormBorderStyle = FormBorderStyle.None; // 不显示标题栏
w1.Dock = System.Windows.Forms.DockStyle.Fill; // 填充panel
this.panel1.Controls.Add(w1); // 添加w1窗体
w1.Show();
}
private void button1_Click(object sender, EventArgs e)
{
if (flag == true && flag1 == true && flag2 == true)
{
w1.Creatchart1();
}
}
下面是子窗口Win1的其中的一个chart的程序
private void Creatchart1()
{
string a = ((Form1)this.Owner).comboBox1.Text;
string b = ((Form1)this.Owner).comboBox2.Text;
string c = ((Form1)this.Owner).comboBox3.Text;
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.DataBind();
chart1.BringToFront();
m.Close();
}
w1.TopLevel = false; 这里改成true时,显示顶级子窗口不能添加到容器控件里
程序启动时this.panel1.Controls.Add(w1); // 添加w1窗体这里显示:非顶级窗体不能显示为模式对话框。在调用 Show 之前应从所有父窗体中移除该窗体