123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace PaintDotNet.Measuring
- {
- public partial class AddingRecordDialog : Form
- {
- private TextBox textBox1;
- private Button button1;
- private Label label2;
- private Label label1;
- /// <summary>
- /// 添加区分
- /// </summary>
- private int addComboboxitemKb;
- /// <summary>
- /// 下拉框项目
- /// </summary>
- public ArrayList dataList;
- public AddingRecordDialog(int addComboboxitemKb)
- {
- this.addComboboxitemKb = addComboboxitemKb;
- InitializeComponent();
- this.Text = PdnResources.GetString("Menu.addingrecord.Text");
- this.button1.Text = PdnResources.GetString("Menu.File.Save.Text");
- this.label1.Text = PdnResources.GetString("Menu.Recordname.Text") + ":";
- }
- private void InitializeComponent()
- {
- this.label1 = new System.Windows.Forms.Label();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.button1 = new System.Windows.Forms.Button();
- this.label2 = new System.Windows.Forms.Label();
- this.SuspendLayout();
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.ForeColor = System.Drawing.SystemColors.MenuText;
- this.label1.Location = new System.Drawing.Point(24, 22);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(65, 12);
- this.label1.TabIndex = 0;
- this.label1.Text = "记录名称:";
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(102, 18);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(232, 21);
- this.textBox1.TabIndex = 1;
- this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(258, 80);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(76, 25);
- this.button1.TabIndex = 2;
- this.button1.Text = "保存";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.ForeColor = System.Drawing.SystemColors.Window;
- this.label2.Location = new System.Drawing.Point(-1, 57);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(353, 12);
- this.label2.TabIndex = 3;
- this.label2.Text = "----------------------------------------------------------";
- //
- // AddingRecordDialog
- //
- this.BackColor = System.Drawing.SystemColors.Control;
- this.ClientSize = new System.Drawing.Size(346, 115);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.button1);
- this.Controls.Add(this.textBox1);
- this.Controls.Add(this.label1);
- this.MaximizeBox = false;
- this.MaximumSize = new System.Drawing.Size(362, 154);
- this.MinimizeBox = false;
- this.MinimumSize = new System.Drawing.Size(362, 154);
- this.Name = "AddingRecordDialog";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
- this.Text = "新增";
- this.TopMost = true;
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
- e.Handled = true;
- //小数点的处理
- if ((int)e.KeyChar == 46)
- {
- if (textBox1.Text.Length <= 0)
- e.Handled = true; //小数点不能在第一位
- else
- {
- float f;
- float oldf;
- bool b1 = false, b2 = false;
- b1 = float.TryParse(textBox1.Text, out oldf);
- b2 = float.TryParse(textBox1.Text + e.KeyChar.ToString(), out f);
- if (b2 == false)
- {
- if (b1 == true)
- e.Handled = true;
- else
- e.Handled = false;
- }
- }
- }
- }
- /// <summary>
- /// 添加按钮按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if(string.IsNullOrEmpty(this.textBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.namecannotbeEmpty.text")+"!", PdnResources.GetString("Menu.alert.text"));
- return;
- }
- if(this.dataList != null && this.dataList.Contains(new System.Collections.DictionaryEntry(Convert.ToDecimal(this.textBox1.Text), this.textBox1.Text + "X")))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Alreadyexists.Text")+"!", PdnResources.GetString("Menu.alert.text"));
- }
- else
- {
- TheoreticalScaleDialog.addComboboxitem = new System.Collections.DictionaryEntry(Convert.ToDecimal(this.textBox1.Text), this.textBox1.Text + "X");
- TheoreticalScaleDialog.addComboboxitemKb = this.addComboboxitemKb;
- TheoreticalScaleDialog theoreticalScaleDialog = (TheoreticalScaleDialog)this.Owner;
- theoreticalScaleDialog.RefreshListView();
- this.Close();
- }
- }
- }
- }
|