From 2141e29593c22e8cc8ff2be6db42c7bdbe7a8b99 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 25 Dec 2018 17:55:56 +0200 Subject: [PATCH] EnterKeyForm code now is more readable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) Сode has been divided into blocks and commented. 2) Almost all names now starts from an uppercase. --- Crypto Notepad/EnterKeyForm.Designer.cs | 114 ++++++++++++------------ Crypto Notepad/EnterKeyForm.cs | 93 ++++++++++--------- 2 files changed, 106 insertions(+), 101 deletions(-) diff --git a/Crypto Notepad/EnterKeyForm.Designer.cs b/Crypto Notepad/EnterKeyForm.Designer.cs index 0dc562e..1bdfabe 100644 --- a/Crypto Notepad/EnterKeyForm.Designer.cs +++ b/Crypto Notepad/EnterKeyForm.Designer.cs @@ -29,76 +29,76 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.button1 = new System.Windows.Forms.Button(); + this.KeyTextBox = new System.Windows.Forms.TextBox(); + this.OkButton = new System.Windows.Forms.Button(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.EyePictureBox = new System.Windows.Forms.PictureBox(); this.panel1 = new System.Windows.Forms.Panel(); - this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.KeyPictureBox = new System.Windows.Forms.PictureBox(); this.label1 = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox)).BeginInit(); this.panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.KeyPictureBox)).BeginInit(); this.SuspendLayout(); // - // textBox1 + // KeyTextBox // - this.textBox1.Location = new System.Drawing.Point(64, 39); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(100, 20); - this.textBox1.TabIndex = 0; - this.textBox1.UseSystemPasswordChar = true; - this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); - this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown); + this.KeyTextBox.Location = new System.Drawing.Point(64, 39); + this.KeyTextBox.Name = "KeyTextBox"; + this.KeyTextBox.Size = new System.Drawing.Size(100, 20); + this.KeyTextBox.TabIndex = 0; + this.KeyTextBox.UseSystemPasswordChar = true; + this.KeyTextBox.TextChanged += new System.EventHandler(this.KeyTextBox_TextChanged); + this.KeyTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.KeyTextBox_KeyDown); // - // button1 + // OkButton // - this.button1.Enabled = false; - this.button1.Location = new System.Drawing.Point(113, 79); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 1; - this.button1.Text = "OK"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); + this.OkButton.Enabled = false; + this.OkButton.Location = new System.Drawing.Point(112, 79); + this.OkButton.Name = "OkButton"; + this.OkButton.Size = new System.Drawing.Size(75, 23); + this.OkButton.TabIndex = 1; + this.OkButton.Text = "OK"; + this.OkButton.UseVisualStyleBackColor = true; + this.OkButton.Click += new System.EventHandler(this.OkButton_Click); // - // pictureBox1 + // EyePictureBox // - this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand; - this.pictureBox1.Image = global::Crypto_Notepad.Properties.Resources.eye_half; - this.pictureBox1.InitialImage = global::Crypto_Notepad.Properties.Resources.eye_half; - this.pictureBox1.Location = new System.Drawing.Point(163, 39); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(18, 20); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox1.TabIndex = 3; - this.pictureBox1.TabStop = false; - this.toolTip1.SetToolTip(this.pictureBox1, "Show key"); - this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); + this.EyePictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.EyePictureBox.Cursor = System.Windows.Forms.Cursors.Hand; + this.EyePictureBox.Image = global::Crypto_Notepad.Properties.Resources.eye_half; + this.EyePictureBox.InitialImage = global::Crypto_Notepad.Properties.Resources.eye_half; + this.EyePictureBox.Location = new System.Drawing.Point(163, 39); + this.EyePictureBox.Name = "EyePictureBox"; + this.EyePictureBox.Size = new System.Drawing.Size(18, 20); + this.EyePictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.EyePictureBox.TabIndex = 3; + this.EyePictureBox.TabStop = false; + this.toolTip1.SetToolTip(this.EyePictureBox, "Show key"); + this.EyePictureBox.Click += new System.EventHandler(this.EyePictureBox_Click); // // panel1 // this.panel1.BackColor = System.Drawing.Color.White; - this.panel1.Controls.Add(this.pictureBox2); + this.panel1.Controls.Add(this.KeyPictureBox); this.panel1.Controls.Add(this.label1); - this.panel1.Controls.Add(this.textBox1); - this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Controls.Add(this.KeyTextBox); + this.panel1.Controls.Add(this.EyePictureBox); this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(191, 73); this.panel1.TabIndex = 5; // - // pictureBox2 + // KeyPictureBox // - this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pictureBox2.Image = global::Crypto_Notepad.Properties.Resources.key_solid; - this.pictureBox2.Location = new System.Drawing.Point(8, 12); - this.pictureBox2.Name = "pictureBox2"; - this.pictureBox2.Size = new System.Drawing.Size(47, 47); - this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.pictureBox2.TabIndex = 6; - this.pictureBox2.TabStop = false; + this.KeyPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.KeyPictureBox.Image = global::Crypto_Notepad.Properties.Resources.key_solid; + this.KeyPictureBox.Location = new System.Drawing.Point(8, 12); + this.KeyPictureBox.Name = "KeyPictureBox"; + this.KeyPictureBox.Size = new System.Drawing.Size(47, 47); + this.KeyPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.KeyPictureBox.TabIndex = 6; + this.KeyPictureBox.TabStop = false; // // label1 // @@ -115,30 +115,30 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(191, 107); this.Controls.Add(this.panel1); - this.Controls.Add(this.button1); + this.Controls.Add(this.OkButton); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "EnterKeyForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Crypto Notepad"; - this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form2_FormClosed); - this.Load += new System.EventHandler(this.Form2_Load); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.EnterKeyForm_FormClosed); + this.Load += new System.EventHandler(this.EnterKeyForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox)).EndInit(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.KeyPictureBox)).EndInit(); this.ResumeLayout(false); } #endregion - private System.Windows.Forms.Button button1; - private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Button OkButton; + private System.Windows.Forms.PictureBox EyePictureBox; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label1; - private System.Windows.Forms.PictureBox pictureBox2; - public System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.PictureBox KeyPictureBox; + public System.Windows.Forms.TextBox KeyTextBox; } } \ No newline at end of file diff --git a/Crypto Notepad/EnterKeyForm.cs b/Crypto Notepad/EnterKeyForm.cs index eebe1d9..432ef01 100644 --- a/Crypto Notepad/EnterKeyForm.cs +++ b/Crypto Notepad/EnterKeyForm.cs @@ -12,55 +12,60 @@ public EnterKeyForm() InitializeComponent(); } - private void button1_Click(object sender, EventArgs e) + /*Form Events*/ + private void EnterKeyForm_FormClosed(object sender, FormClosedEventArgs e) { - TypedPassword.Value = textBox1.Text; - textBox1.Focus(); - PublicVar.okPressed = true; - this.Hide(); + KeyTextBox.Focus(); } - private void textBox1_TextChanged(object sender, EventArgs e) - { - if (textBox1.Text.Length > 0) - button1.Enabled = true; - else - button1.Enabled = false; - } - - private void textBox1_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter && button1.Enabled) - { - button1_Click(sender, e); - } - } - - private void pictureBox1_Click(object sender, EventArgs e) - { - if (textBox1.UseSystemPasswordChar) - { - textBox1.UseSystemPasswordChar = false; - pictureBox1.Image = Properties.Resources.eye; - return; - } - - if (!textBox1.UseSystemPasswordChar) - { - textBox1.UseSystemPasswordChar = true; - pictureBox1.Image = Properties.Resources.eye_half; - return; - } - } - - private void Form2_FormClosed(object sender, FormClosedEventArgs e) - { - textBox1.Focus(); - } - - private void Form2_Load(object sender, EventArgs e) + private void EnterKeyForm_Load(object sender, EventArgs e) { this.Text = PublicVar.openFileName; } + /*Form Events*/ + + + /*Enter key area*/ + private void KeyTextBox_TextChanged(object sender, EventArgs e) + { + if (KeyTextBox.Text.Length > 0) + OkButton.Enabled = true; + else + OkButton.Enabled = false; + } + + private void KeyTextBox_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter && OkButton.Enabled) + { + OkButton_Click(sender, e); + } + } + + private void EyePictureBox_Click(object sender, EventArgs e) + { + if (KeyTextBox.UseSystemPasswordChar) + { + KeyTextBox.UseSystemPasswordChar = false; + EyePictureBox.Image = Properties.Resources.eye; + } + else + { + KeyTextBox.UseSystemPasswordChar = true; + EyePictureBox.Image = Properties.Resources.eye_half; + } + } + /*Enter key area*/ + + + /*Buttons*/ + private void OkButton_Click(object sender, EventArgs e) + { + TypedPassword.Value = KeyTextBox.Text; + KeyTextBox.Focus(); + PublicVar.okPressed = true; + this.Hide(); + } + /*Buttons*/ } }