private void button1_Click_1(object sender, EventArgs e) { ck = new CheckBox[11]; cd = new ColorDialog(); bt = new Button[11]; setchart = new Form(); //setchart.Name = "uu"; setchart.FormClosing += new FormClosingEventHandler(setchart_FormClosing); tp = new TableLayoutPanel(); setchart.Text = "图表设置"; tp.Dock = DockStyle.Fill; string[][] aa = SaveStatic.ReadMultiTxt(Application.StartupPath + "\\chartset.txt"); for (int i = 0; i < 11; i++) { //tp.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); bt[i] = new Button(); ck[i] = new CheckBox(); ck[i].Checked = Convert.ToBoolean(aa[i][0]); ck[i].Text = lineName[i]; bt[i].BackColor = Color.FromArgb(int.Parse(aa[i][1])); bt[i].Size = ck[i].Size; bt[i].Tag = i; bt[i].Click += new EventHandler(button_click); tp.Controls.Add(ck[i], 0, i); tp.Controls.Add(bt[i], 1, i); } setchart.Height = 380; setchart.Width = 250; setchart.Controls.Add(tp); //txtChangeFlag = true; setchart.TopMost = true; setchart.FormBorderStyle = FormBorderStyle.FixedToolWindow; setchart.StartPosition = FormStartPosition.CenterScreen; setchart.ShowDialog(); }
public void fresh() { if (Flag) { Flag = false; flowLayoutPanel1.Controls.Clear(); if (File.Exists(Application.StartupPath + "\\chartset.txt")) { string[][] aa = SaveStatic.ReadMultiTxt(Application.StartupPath + "\\chartset.txt"); visible[0] = Convert.ToBoolean(aa[0][0]); visible[1] = Convert.ToBoolean(aa[1][0]); visible[2] = Convert.ToBoolean(aa[2][0]); visible[3] = Convert.ToBoolean(aa[3][0]); visible[4] = Convert.ToBoolean(aa[4][0]); visible[5] = Convert.ToBoolean(aa[5][0]); visible[6] = Convert.ToBoolean(aa[6][0]); visible[7] = Convert.ToBoolean(aa[7][0]); DownLineShow = Convert.ToBoolean(aa[8][0]); UpLineShow = Convert.ToBoolean(aa[9][0]); MidLineShow = Convert.ToBoolean(aa[10][0]); c_color1 = Color.FromArgb(int.Parse(aa[0][1])); c_color2 = Color.FromArgb(int.Parse(aa[1][1])); c_color3 = Color.FromArgb(int.Parse(aa[2][1])); c_color4 = Color.FromArgb(int.Parse(aa[3][1])); c_color5 = Color.FromArgb(int.Parse(aa[4][1])); c_color6 = Color.FromArgb(int.Parse(aa[5][1])); c_color7 = Color.FromArgb(int.Parse(aa[6][1])); c_color8 = Color.FromArgb(int.Parse(aa[7][1])); C_colorLow = Color.FromArgb(int.Parse(aa[8][1])); C_colorHigh = Color.FromArgb(int.Parse(aa[9][1])); C_colorMid = Color.FromArgb(int.Parse(aa[10][1])); } else { MessageBox.Show("文件chartset.txt丢失!"); return; } if (visible[0]) { chart1.Series["Series1"].Enabled = true; TableLayoutPanel tp = new TableLayoutPanel(); tp.AutoSize = true; Label lab1 = new Label(); lab1.AutoSize = true; lab1.Text = " "; lab1.BackColor = c_color1; Label lab2 = new Label(); lab2.AutoSize = true; lab2.Text = " "; lab2.Text = lineName[0]; tp.Controls.Add(lab1, 0, 0); tp.Controls.Add(lab2, 1, 0); flowLayoutPanel1.Controls.Add(tp); } else { chart1.Series["Series1"].Enabled = false; } if (visible[1]) { chart1.Series["Series2"].Enabled = true; TableLayoutPanel tp = new TableLayoutPanel(); tp.AutoSize = true; Label lab1 = new Label(); lab1.AutoSize = true; lab1.Text = " "; lab1.BackColor = c_color2; Label lab2 = new Label(); lab2.AutoSize = true; lab2.Text = " "; lab2.Text = lineName[1]; tp.Controls.Add(lab1, 0, 0); tp.Controls.Add(lab2, 1, 0); flowLayoutPanel1.Controls.Add(tp); } else { chart1.Series["Series2"].Enabled = false; } if (visible[2]) { chart1.Series["Series3"].Enabled = true; TableLayoutPanel tp = new TableLayoutPanel(); tp.AutoSize = true; Label lab1 = new Label(); lab1.AutoSize = true; lab1.Text = " "; lab1.BackColor = c_color3; Label lab2 = new Label(); lab2.AutoSize = true; lab2.Text = " "; lab2.Text = lineName[2]; tp.Controls.Add(lab1, 0, 0); tp.Controls.Add(lab2, 1, 0); flowLayoutPanel1.Controls.Add(tp); } else { chart1.Series["Series3"].Enabled = false; } if (visible[3]) { chart1.Series["Series4"].Enabled = true; TableLayoutPanel tp = new TableLayoutPanel(); tp.AutoSize = true; Label lab1 = new Label(); lab1.AutoSize = true; lab1.Text = " "; lab1.BackColor = c_color4; Label lab2 = new Label(); lab2.AutoSize = true; lab2.Text = " "; lab2.Text = lineName[3]; tp.Controls.Add(lab1, 0, 0); tp.Controls.Add(lab2, 1, 0); flowLayoutPanel1.Controls.Add(tp); } else { chart1.Series["Series4"].Enabled = false; } if (visible[4]) { chart1.Series["Series5"].Enabled = true; TableLayoutPanel tp = new TableLayoutPanel(); tp.AutoSize = true; Label lab1 = new Label(); lab1.AutoSize = true; lab1.Text = " "; lab1.BackColor = c_color5; Label lab2 = new Label(); lab2.AutoSize = true; lab2.Text = " "; lab2.Text = lineName[4]; tp.Controls.Add(lab1, 0, 0); tp.Controls.Add(lab2, 1, 0); flowLayoutPanel1.Controls.Add(tp); } else { chart1.Series["Series5"].Enabled = false; } if (visible[5]) { chart1.Series["Series6"].Enabled = true; TableLayoutPanel tp = new TableLayoutPanel(); tp.AutoSize = true; Label lab1 = new Label(); lab1.AutoSize = true; lab1.Text = " "; lab1.BackColor = c_color6; Label lab2 = new Label(); lab2.AutoSize = true; lab2.Text = " "; lab2.Text = lineName[5]; tp.Controls.Add(lab1, 0, 0); tp.Controls.Add(lab2, 1, 0); flowLayoutPanel1.Controls.Add(tp); } else { chart1.Series["Series6"].Enabled = false; } if (visible[6]) { chart1.Series["Series7"].Enabled = true; TableLayoutPanel tp = new TableLayoutPanel(); tp.AutoSize = true; Label lab1 = new Label(); lab1.AutoSize = true; lab1.Text = " "; lab1.BackColor = c_color7; Label lab2 = new Label(); lab2.AutoSize = true; lab2.Text = " "; lab2.Text = lineName[6]; tp.Controls.Add(lab1, 0, 0); tp.Controls.Add(lab2, 1, 0); flowLayoutPanel1.Controls.Add(tp); } else { chart1.Series["Series7"].Enabled = false; } if (visible[7]) { chart1.Series["Series8"].Enabled = true; TableLayoutPanel tp = new TableLayoutPanel(); tp.AutoSize = true; Label lab1 = new Label(); lab1.AutoSize = true; lab1.Text = " "; lab1.BackColor = c_color8; Label lab2 = new Label(); lab2.AutoSize = true; lab2.Text = " "; lab2.Text = lineName[7]; tp.Controls.Add(lab1, 0, 0); tp.Controls.Add(lab2, 1, 0); flowLayoutPanel1.Controls.Add(tp); } else { chart1.Series["Series8"].Enabled = false; } } if (listdatabinPath[0] != "") { if (SaveStatic.ReadMultiTxt(listdatabinPath[0]) == null) { return; } string[][] _d0 = SaveStatic.ReadMultiTxt(listdatabinPath[0]); string[][] d0 = Conver.TransPosition(_d0); listX[0] = Array.ConvertAll(d0[0].ToArray(), Convert.ToSingle).ToList(); listY[0] = Array.ConvertAll(d0[1].ToArray(), Convert.ToSingle).ToList(); chart1.Series["Series1"].Points.DataBindXY(listX[0], listY[0]); chart1.Series["Series1"].Color = c_color1; } if (listdatabinPath[1] != "") { if (SaveStatic.ReadMultiTxt(listdatabinPath[1]) == null) { return; } string[][] _d1 = SaveStatic.ReadMultiTxt(listdatabinPath[1]); string[][] d1 = Conver.TransPosition(_d1); listX[1] = Array.ConvertAll(d1[0].ToArray(), Convert.ToSingle).ToList(); listY[1] = Array.ConvertAll(d1[1].ToArray(), Convert.ToSingle).ToList(); chart1.Series["Series2"].Points.DataBindXY(listX[1], listY[1]); chart1.Series["Series2"].Color = c_color2; } if (listdatabinPath[2] != "") { if (SaveStatic.ReadMultiTxt(listdatabinPath[2]) == null) { return; } string[][] _d2 = SaveStatic.ReadMultiTxt(listdatabinPath[2]); string[][] d2 = Conver.TransPosition(_d2); listX[2] = Array.ConvertAll(d2[0].ToArray(), Convert.ToSingle).ToList(); listY[2] = Array.ConvertAll(d2[1].ToArray(), Convert.ToSingle).ToList(); chart1.Series["Series3"].Points.DataBindXY(listX[2], listY[2]); chart1.Series["Series3"].Color = c_color3; } if (listdatabinPath[3] != "") { if (SaveStatic.ReadMultiTxt(listdatabinPath[3]) == null) { return; } string[][] _d3 = SaveStatic.ReadMultiTxt(listdatabinPath[3]); string[][] d3 = Conver.TransPosition(_d3); listX[3] = Array.ConvertAll(d3[0].ToArray(), Convert.ToSingle).ToList(); listY[3] = Array.ConvertAll(d3[1].ToArray(), Convert.ToSingle).ToList(); chart1.Series["Series4"].Points.DataBindXY(listX[3], listY[3]); chart1.Series["Series4"].Color = c_color4; } if (listdatabinPath[4] != "") { if (SaveStatic.ReadMultiTxt(listdatabinPath[4]) == null) { return; } string[][] _d4 = SaveStatic.ReadMultiTxt(listdatabinPath[4]); string[][] d4 = Conver.TransPosition(_d4); listX[4] = Array.ConvertAll(d4[0].ToArray(), Convert.ToSingle).ToList(); listY[4] = Array.ConvertAll(d4[1].ToArray(), Convert.ToSingle).ToList(); chart1.Series["Series5"].Points.DataBindXY(listX[4], listY[4]); chart1.Series["Series5"].Color = c_color5; } if (listdatabinPath[5] != "") { if (SaveStatic.ReadMultiTxt(listdatabinPath[5]) == null) { return; } string[][] _d5 = SaveStatic.ReadMultiTxt(listdatabinPath[5]); string[][] d5 = Conver.TransPosition(_d5); listX[5] = Array.ConvertAll(d5[0].ToArray(), Convert.ToSingle).ToList(); listY[5] = Array.ConvertAll(d5[1].ToArray(), Convert.ToSingle).ToList(); chart1.Series["Series6"].Points.DataBindXY(listX[5], listY[5]); chart1.Series["Series6"].Color = c_color6; } if (listdatabinPath[6] != "") { if (SaveStatic.ReadMultiTxt(listdatabinPath[6]) == null) { return; } string[][] _d6 = SaveStatic.ReadMultiTxt(listdatabinPath[6]); string[][] d6 = Conver.TransPosition(_d6); listX[6] = Array.ConvertAll(d6[0].ToArray(), Convert.ToSingle).ToList(); listY[6] = Array.ConvertAll(d6[1].ToArray(), Convert.ToSingle).ToList(); chart1.Series["Series7"].Points.DataBindXY(listX[6], listY[6]); chart1.Series["Series7"].Color = c_color7; } if (listdatabinPath[7] != "") { if (SaveStatic.ReadMultiTxt(listdatabinPath[7]) == null) { return; } string[][] _d7 = SaveStatic.ReadMultiTxt(listdatabinPath[7]); string[][] d7 = Conver.TransPosition(_d7); listX[7] = Array.ConvertAll(d7[0].ToArray(), Convert.ToSingle).ToList(); listY[7] = Array.ConvertAll(d7[1].ToArray(), Convert.ToSingle).ToList(); chart1.Series["Series8"].Points.DataBindXY(listX[7], listY[7]); chart1.Series["Series8"].Color = c_color8; } float[] Xc = new float[8]; for (int i = 0; i < 8; i++) { if (listX[i] != null) { if (listX[i].Count > 0) { Xc[i] = listX[i][listX[i].Count - 1]; } } } X = Xc.Max(); //X = listX[0].Count - 1; if (follow == true) { if (X > showCount) { if (X > chartCount) { chart1.ChartAreas[0].AxisX.Minimum = X - chartCount; } chart1.ChartAreas[0].AxisX.Maximum = X; chart1.ChartAreas[0].AxisX.ScaleView.Zoom(X - showCount + 1, X); } else { chart1.ChartAreas[0].AxisX.Minimum = 0; chart1.ChartAreas[0].AxisX.Maximum = showCount; ZoomReset(); //chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0, totalCount-1); } } else { if (X <= showCount) { chart1.ChartAreas[0].AxisX.Maximum = showCount; ZoomReset(); //chart1.ChartAreas[0].AxisX.ScaleView.Zoom(0, 50); } else { chart1.ChartAreas[0].AxisX.Maximum = X; } } }