private void BtnSave_Click(object sender, EventArgs e) { if (sequence /*sequenceList.Count*/ == NTRSbyDB.Layout.sum)//NTRSjudge.Layout.row * NTRSjudge.Layout.col) { if (sequenceList.Count == NTRSbyDB.Layout.sum) { RegistryKey key = Registry.LocalMachine; RegistryKey software = key.OpenSubKey(@"software\NTRS", true); software.SetValue("Trajectory", sequenceList.ToArray(), RegistryValueKind.MultiString); } MessageBox.Show("保存成功"); this.Close(); if (!Regedit.verifyTrajectory()) { #region 重启 bool isOpen = false; foreach (Form f in Application.OpenForms) { if (f.Name == "Main") { isOpen = true; } } if (isOpen)//主串口打开了,重启 { Application.Exit(); System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); } #endregion } } else { MessageBox.Show("保存失败,运动轨迹存在空设定"); } }
public Main() { //CheckForIllegalCrossThreadCalls = false; main = this; InitializeComponent(); //显示版本号 this.Text += "_" + Application.ProductVersion.ToString(); //新建文件夹(log、pqm、sum) Document.CreateDocument(); //创建注册表文件 try { Registry.LocalMachine.CreateSubKey(@"software\NTRS"); } catch (Exception ex) { MessageBox.Show(ex.Message); Environment.Exit(0); } //验证(串口) if (!Regedit.verifyPort()) { checkPort: DialogResult dr = MessageBox.Show("串口验证失败,\n按确定键重新设置串口属性或关闭程序。", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dr == DialogResult.No) { Environment.Exit(0); } new Port().ShowDialog(); if (!Regedit.verifyPort()) { goto checkPort; } } //验证(运动轨迹) if (!Regedit.verifyTrajectory()) { checkTrajectory: DialogResult dr = MessageBox.Show("运动轨迹验证失败,\n按确定键重新设置运动轨迹或关闭程序。", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dr == DialogResult.No) { Environment.Exit(0); } new Trajectory().ShowDialog(); if (!Regedit.verifyTrajectory()) { goto checkTrajectory; } } #region 布局 #region string[] items = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"DisplayDetail").Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int y = 0; foreach (string item in items) { y += 40; string[] detail = item.Split(','); TextBox txt = new TextBox() { Size = new Size(245, 33) }; txt.Location = new Point(15, -15 + y); txt.Text = detail[0]; txt.ForeColor = ColorTranslator.FromHtml(detail[1]); txt.BackColor = ColorTranslator.FromHtml(detail[2]); gbDetail.Controls.Add(txt); } #endregion #region TlpLayout TlpLayout.RowCount = NTRSbyDB.Layout.row; TlpLayout.ColumnCount = NTRSbyDB.Layout.col; for (int i = 0; i < NTRSbyDB.Layout.row; i++) { TlpLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); } for (int i = 0; i < NTRSbyDB.Layout.col; i++) { TlpLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); } #endregion #endregion TlpLayout_Width = TlpLayout.Width; }
public Port() { InitializeComponent(); CmbPortName1.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames()); CmbPortName2.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames()); //载入生产模式 switch (Main.mode) { case Main.Mode.旧机器API2: 旧机器API2ToolStripMenuItem.Checked = true; GrpPort1.Enabled = true; break; case Main.Mode.无串口: 无串口ToolStripMenuItem.Checked = true; GrpPort1.Enabled = false; GrpPort2.Enabled = false; break; } #region load注册表 if (Regedit.isRegeditKeyExit("Port")) { RegistryKey myreg = Registry.LocalMachine.OpenSubKey(@"software\NTRS"); String[] valueList = (String[])(myreg.GetValue("Port")); if (valueList.Length == 5 || valueList.Length == 10) { CmbPortName1.Text = valueList[0]; CmbBaudRate1.Text = valueList[1]; CmbParity1.Text = valueList[2]; CmbDataBits1.Text = valueList[3]; CmbStopBits1.Text = valueList[4]; if (valueList.Length == 10) { CmbPortName2.Text = valueList[5]; CmbBaudRate2.Text = valueList[6]; CmbParity2.Text = valueList[7]; CmbDataBits2.Text = valueList[8]; CmbStopBits2.Text = valueList[9]; } } } if (Regedit.isRegeditKeyExit("Identifier")) { RegistryKey myreg = Registry.LocalMachine.OpenSubKey(@"software\NTRS"); identifier = (String)(myreg.GetValue("Identifier")); switch (identifier) { case "\r": TxtIdentifier.Text = "[CR]"; break; case "\n": TxtIdentifier.Text = "[LF]"; break; default: TxtIdentifier.Text = identifier; break; } } #endregion }
public Trajectory() { InitializeComponent(); #region 布局 TlpLayout.RowCount = NTRSbyDB.Layout.row; TlpLayout.ColumnCount = NTRSbyDB.Layout.col; for (int i = 0; i < NTRSbyDB.Layout.row; i++) { TlpLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); } for (int i = 0; i < NTRSbyDB.Layout.col; i++) { TlpLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); } for (int i = 0; i < NTRSbyDB.Layout.row; i++) { for (int j = 0; j < NTRSbyDB.Layout.col; j++) { Label label = new Label(); label.Dock = DockStyle.Fill; label.BackColor = Color.Red; label.Text = "\r\n\r\n\r\n(" + (j + 1).ToString() + "," + (i + 1).ToString() + ")"; label.Click += new EventHandler(clickMark); TlpLayout.Controls.Add(label, j, i); //下面这句要是在行和列不够的情况下,会建到100行1000列 //tableLayoutPanel1.Controls.Add(label1, 100, 1000); } } void clickMark(object sender, EventArgs e) { Label label = (Label)sender; label.Text = label.Text.Insert(0, (++sequence).ToString()); label.BackColor = Color.Lime; label.Enabled = false; sequenceList.Add((TlpLayout.GetColumn(label) + 1).ToString() + "," + (TlpLayout.GetRow(label) + 1).ToString()); } #endregion //存在key且通过验证就显示次序顺序 #region load注册表 if (Regedit.isRegeditKeyExit("Trajectory")) { if (!Regedit.verifyTrajectory()) { return; } RegistryKey myreg = Registry.LocalMachine.OpenSubKey(@"software\NTRS"); String[] sequenceList = (String[])(myreg.GetValue("Trajectory")); //验证:读取的字符串能匹配上布局的定义坐标(1,1\1,2等) foreach (string str in sequenceList) { //遍历控件对比 for (int i = 0; i < TlpLayout.Controls.Count; i++) { if (TlpLayout.Controls[i].Text.Contains(str)) { TlpLayout.Controls[i].BackColor = Color.Lime; TlpLayout.Controls[i].Enabled = false; TlpLayout.Controls[i].Text = TlpLayout.Controls[i].Text.Insert(0, (++sequence).ToString()); break; } #region Regedit.verifyTrajectory()覆盖该过程 ////全部验证成功才显示次序(只要有一个验证不了,全部取消) ////Regedit.verifyTrajectory()一定要元素相等且相同才可进这里,所以不需要下面这 //if (i == tableLayoutPanel1.Controls.Count-1) //{ // cancel_btn_Click(new object (), new EventArgs ()); // return; //} #endregion } #region 索引(比较复杂,用遍历方法实现) ////tableLayoutPanel1.Controls.Add(label, j, i); ////string test=tableLayoutPanel1.Controls[1].Text; ////string a=tableLayoutPanel1.Controls[0,1].Text; //int row=int.Parse(str.Split(',')[0]); //int col = int.Parse(str.Split(',')[1]); ////2,2 //int r=row % NTRSjudge.Layout.row; //int c = col % NTRSjudge.Layout.col; #endregion } } #endregion }