From 1febb7e3fa22674650732dbb374f4b428a697233 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 25 Dec 2018 17:55:15 +0200 Subject: [PATCH] ChangeKeyForm 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/ChangeKeyForm.Designer.cs | 222 +++++++++++------------ Crypto Notepad/ChangeKeyForm.cs | 120 ++++++------ 2 files changed, 170 insertions(+), 172 deletions(-) diff --git a/Crypto Notepad/ChangeKeyForm.Designer.cs b/Crypto Notepad/ChangeKeyForm.Designer.cs index 5843a9c..f81ef1c 100644 --- a/Crypto Notepad/ChangeKeyForm.Designer.cs +++ b/Crypto Notepad/ChangeKeyForm.Designer.cs @@ -28,141 +28,141 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.textBox1 = new System.Windows.Forms.TextBox(); - this.textBox2 = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); + this.OldKeyTextBox = new System.Windows.Forms.TextBox(); + this.NewKeyTextBox = new System.Windows.Forms.TextBox(); + this.OldKeyLabel = new System.Windows.Forms.Label(); + this.NewKeyLabel = new System.Windows.Forms.Label(); + this.AcceptButton = new System.Windows.Forms.Button(); this.panel1 = new System.Windows.Forms.Panel(); - this.pictureBox3 = new System.Windows.Forms.PictureBox(); - this.pictureBox2 = new System.Windows.Forms.PictureBox(); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.statusLabel = new System.Windows.Forms.Label(); + this.KeysPictureBox = new System.Windows.Forms.PictureBox(); + this.EyePictureBox2 = new System.Windows.Forms.PictureBox(); + this.EyePictureBox1 = new System.Windows.Forms.PictureBox(); + this.StatusLabel = new System.Windows.Forms.Label(); this.panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.KeysPictureBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox1)).BeginInit(); this.SuspendLayout(); // - // textBox1 + // OldKeyTextBox // - this.textBox1.Location = new System.Drawing.Point(120, 9); - 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.OldKeyTextBox.Location = new System.Drawing.Point(120, 9); + this.OldKeyTextBox.Name = "OldKeyTextBox"; + this.OldKeyTextBox.Size = new System.Drawing.Size(100, 20); + this.OldKeyTextBox.TabIndex = 0; + this.OldKeyTextBox.UseSystemPasswordChar = true; + this.OldKeyTextBox.TextChanged += new System.EventHandler(this.OldKeyTextBox_TextChanged); // - // textBox2 + // NewKeyTextBox // - this.textBox2.Location = new System.Drawing.Point(120, 43); - this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(100, 20); - this.textBox2.TabIndex = 1; - this.textBox2.UseSystemPasswordChar = true; - this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged); + this.NewKeyTextBox.Location = new System.Drawing.Point(120, 43); + this.NewKeyTextBox.Name = "NewKeyTextBox"; + this.NewKeyTextBox.Size = new System.Drawing.Size(100, 20); + this.NewKeyTextBox.TabIndex = 1; + this.NewKeyTextBox.UseSystemPasswordChar = true; + this.NewKeyTextBox.TextChanged += new System.EventHandler(this.NewKeyTextBox_TextChanged); // - // label1 + // OldKeyLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(61, 12); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(47, 13); - this.label1.TabIndex = 2; - this.label1.Text = "Old Key:"; + this.OldKeyLabel.AutoSize = true; + this.OldKeyLabel.Location = new System.Drawing.Point(61, 12); + this.OldKeyLabel.Name = "OldKeyLabel"; + this.OldKeyLabel.Size = new System.Drawing.Size(47, 13); + this.OldKeyLabel.TabIndex = 2; + this.OldKeyLabel.Text = "Old Key:"; // - // label2 + // NewKeyLabel // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(61, 46); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(53, 13); - this.label2.TabIndex = 3; - this.label2.Text = "New Key:"; + this.NewKeyLabel.AutoSize = true; + this.NewKeyLabel.Location = new System.Drawing.Point(61, 46); + this.NewKeyLabel.Name = "NewKeyLabel"; + this.NewKeyLabel.Size = new System.Drawing.Size(53, 13); + this.NewKeyLabel.TabIndex = 3; + this.NewKeyLabel.Text = "New Key:"; // - // button1 + // AcceptButton // - this.button1.Enabled = false; - this.button1.Location = new System.Drawing.Point(206, 82); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(53, 23); - this.button1.TabIndex = 4; - this.button1.Text = "Accept"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); + this.AcceptButton.Enabled = false; + this.AcceptButton.Location = new System.Drawing.Point(206, 82); + this.AcceptButton.Name = "AcceptButton"; + this.AcceptButton.Size = new System.Drawing.Size(53, 23); + this.AcceptButton.TabIndex = 4; + this.AcceptButton.Text = "Accept"; + this.AcceptButton.UseVisualStyleBackColor = true; + this.AcceptButton.Click += new System.EventHandler(this.AcceptButton_Click); // // panel1 // this.panel1.BackColor = System.Drawing.Color.White; - this.panel1.Controls.Add(this.pictureBox3); - this.panel1.Controls.Add(this.pictureBox2); - this.panel1.Controls.Add(this.label1); - this.panel1.Controls.Add(this.pictureBox1); - this.panel1.Controls.Add(this.textBox1); - this.panel1.Controls.Add(this.textBox2); - this.panel1.Controls.Add(this.label2); + this.panel1.Controls.Add(this.KeysPictureBox); + this.panel1.Controls.Add(this.EyePictureBox2); + this.panel1.Controls.Add(this.OldKeyLabel); + this.panel1.Controls.Add(this.EyePictureBox1); + this.panel1.Controls.Add(this.OldKeyTextBox); + this.panel1.Controls.Add(this.NewKeyTextBox); + this.panel1.Controls.Add(this.NewKeyLabel); this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(262, 75); this.panel1.TabIndex = 6; // - // pictureBox3 + // KeysPictureBox // - this.pictureBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pictureBox3.Image = global::Crypto_Notepad.Properties.Resources.gnupg_keys; - this.pictureBox3.Location = new System.Drawing.Point(8, 12); - this.pictureBox3.Name = "pictureBox3"; - this.pictureBox3.Size = new System.Drawing.Size(47, 47); - this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.pictureBox3.TabIndex = 7; - this.pictureBox3.TabStop = false; + this.KeysPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.KeysPictureBox.Image = global::Crypto_Notepad.Properties.Resources.gnupg_keys; + this.KeysPictureBox.Location = new System.Drawing.Point(8, 12); + this.KeysPictureBox.Name = "KeysPictureBox"; + this.KeysPictureBox.Size = new System.Drawing.Size(47, 47); + this.KeysPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.KeysPictureBox.TabIndex = 7; + this.KeysPictureBox.TabStop = false; // - // pictureBox2 + // EyePictureBox2 // - this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pictureBox2.Cursor = System.Windows.Forms.Cursors.Hand; - this.pictureBox2.Image = global::Crypto_Notepad.Properties.Resources.eye_half; - this.pictureBox2.Location = new System.Drawing.Point(219, 43); - this.pictureBox2.Name = "pictureBox2"; - this.pictureBox2.Size = new System.Drawing.Size(32, 20); - this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.pictureBox2.TabIndex = 5; - this.pictureBox2.TabStop = false; - this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click); + this.EyePictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.EyePictureBox2.Cursor = System.Windows.Forms.Cursors.Hand; + this.EyePictureBox2.Image = global::Crypto_Notepad.Properties.Resources.eye_half; + this.EyePictureBox2.Location = new System.Drawing.Point(219, 43); + this.EyePictureBox2.Name = "EyePictureBox2"; + this.EyePictureBox2.Size = new System.Drawing.Size(32, 20); + this.EyePictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.EyePictureBox2.TabIndex = 5; + this.EyePictureBox2.TabStop = false; + this.EyePictureBox2.Click += new System.EventHandler(this.EyePictureBox2_Click); // - // pictureBox1 + // EyePictureBox1 // - 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.Location = new System.Drawing.Point(219, 9); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(32, 20); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; - this.pictureBox1.TabIndex = 5; - this.pictureBox1.TabStop = false; - this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); + this.EyePictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.EyePictureBox1.Cursor = System.Windows.Forms.Cursors.Hand; + this.EyePictureBox1.Image = global::Crypto_Notepad.Properties.Resources.eye_half; + this.EyePictureBox1.Location = new System.Drawing.Point(219, 9); + this.EyePictureBox1.Name = "EyePictureBox1"; + this.EyePictureBox1.Size = new System.Drawing.Size(32, 20); + this.EyePictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; + this.EyePictureBox1.TabIndex = 5; + this.EyePictureBox1.TabStop = false; + this.EyePictureBox1.Click += new System.EventHandler(this.EyePictureBox1_Click); // - // statusLabel + // StatusLabel // - this.statusLabel.AutoSize = true; - this.statusLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.statusLabel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); - this.statusLabel.Location = new System.Drawing.Point(5, 87); - this.statusLabel.Name = "statusLabel"; - this.statusLabel.Size = new System.Drawing.Size(43, 16); - this.statusLabel.TabIndex = 7; - this.statusLabel.Text = "status"; - this.statusLabel.Visible = false; + this.StatusLabel.AutoSize = true; + this.StatusLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.StatusLabel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); + this.StatusLabel.Location = new System.Drawing.Point(5, 87); + this.StatusLabel.Name = "StatusLabel"; + this.StatusLabel.Size = new System.Drawing.Size(43, 16); + this.StatusLabel.TabIndex = 7; + this.StatusLabel.Text = "status"; + this.StatusLabel.Visible = false; // // ChangeKeyForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(263, 111); - this.Controls.Add(this.statusLabel); + this.Controls.Add(this.StatusLabel); this.Controls.Add(this.panel1); - this.Controls.Add(this.button1); + this.Controls.Add(this.AcceptButton); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; @@ -171,9 +171,9 @@ private void InitializeComponent() this.Text = "Change Key"; this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.KeysPictureBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -181,15 +181,15 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.TextBox textBox1; - private System.Windows.Forms.TextBox textBox2; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.PictureBox pictureBox1; - private System.Windows.Forms.PictureBox pictureBox2; + private System.Windows.Forms.TextBox OldKeyTextBox; + private System.Windows.Forms.TextBox NewKeyTextBox; + private System.Windows.Forms.Label OldKeyLabel; + private System.Windows.Forms.Label NewKeyLabel; + private System.Windows.Forms.Button AcceptButton; + private System.Windows.Forms.PictureBox EyePictureBox1; + private System.Windows.Forms.PictureBox EyePictureBox2; private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.PictureBox pictureBox3; - private System.Windows.Forms.Label statusLabel; + private System.Windows.Forms.PictureBox KeysPictureBox; + private System.Windows.Forms.Label StatusLabel; } } \ No newline at end of file diff --git a/Crypto Notepad/ChangeKeyForm.cs b/Crypto Notepad/ChangeKeyForm.cs index c09a35e..9a40c70 100644 --- a/Crypto Notepad/ChangeKeyForm.cs +++ b/Crypto Notepad/ChangeKeyForm.cs @@ -12,100 +12,98 @@ public ChangeKeyForm() InitializeComponent(); } - private async void button1_Click(object sender, EventArgs e) + /*Buttons*/ + private async void AcceptButton_Click(object sender, EventArgs e) { - if (textBox1.Text == PublicVar.encryptionKey.Get() & textBox1.Text != textBox2.Text) + if (OldKeyTextBox.Text == PublicVar.encryptionKey.Get() && OldKeyTextBox.Text != NewKeyTextBox.Text) { - PublicVar.encryptionKey.Set(textBox2.Text); + PublicVar.encryptionKey.Set(NewKeyTextBox.Text); PublicVar.keyChanged = true; - textBox1.Text = ""; - textBox2.Text = ""; - statusLabel.Text = "Key was successfully changed"; - statusLabel.Visible = true; - button1.Enabled = false; + OldKeyTextBox.Text = ""; + NewKeyTextBox.Text = ""; + StatusLabel.Text = "Key was successfully changed"; + StatusLabel.Visible = true; + AcceptButton.Enabled = false; await Task.Delay(2000); - statusLabel.Text = ""; + StatusLabel.Text = ""; return; } - if (textBox1.Text != PublicVar.encryptionKey.Get()) + if (OldKeyTextBox.Text != PublicVar.encryptionKey.Get()) { SystemSounds.Beep.Play(); - statusLabel.Text = "Invalid old key"; - statusLabel.Visible = true; - textBox1.Text = ""; - textBox2.Text = ""; + StatusLabel.Text = "Invalid old key"; + StatusLabel.Visible = true; + OldKeyTextBox.Text = ""; + NewKeyTextBox.Text = ""; return; } - if (textBox1.Text == textBox2.Text) + if (OldKeyTextBox.Text == NewKeyTextBox.Text) { SystemSounds.Beep.Play(); - statusLabel.Text = "New key is the same as old"; - statusLabel.Visible = true; - textBox1.Text = ""; - textBox2.Text = ""; + StatusLabel.Text = "New key is the same as old"; + StatusLabel.Visible = true; + OldKeyTextBox.Text = ""; + NewKeyTextBox.Text = ""; return; } } + /*Buttons*/ - private void pictureBox1_Click(object sender, EventArgs e) + + /*Enter keys area*/ + private void EyePictureBox1_Click(object sender, EventArgs e) { - if (textBox1.UseSystemPasswordChar) + if (OldKeyTextBox.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 pictureBox2_Click(object sender, EventArgs e) - { - if (textBox2.UseSystemPasswordChar) - { - textBox2.UseSystemPasswordChar = false; - pictureBox2.Image = Properties.Resources.eye; - return; - } - - if (!textBox2.UseSystemPasswordChar) - { - textBox2.UseSystemPasswordChar = true; - pictureBox2.Image = Properties.Resources.eye_half; - return; - } - } - - private void textBox1_TextChanged(object sender, EventArgs e) - { - if (textBox1.Text.Length > 0 & textBox2.Text.Length > 0) - { - button1.Enabled = true; + OldKeyTextBox.UseSystemPasswordChar = false; + EyePictureBox1.Image = Properties.Resources.eye; } else { - button1.Enabled = false; + OldKeyTextBox.UseSystemPasswordChar = true; + EyePictureBox1.Image = Properties.Resources.eye_half; } } - private void textBox2_TextChanged(object sender, EventArgs e) + private void EyePictureBox2_Click(object sender, EventArgs e) { - if (textBox1.Text.Length > 0 & textBox2.Text.Length > 0) + if (NewKeyTextBox.UseSystemPasswordChar) { - button1.Enabled = true; + NewKeyTextBox.UseSystemPasswordChar = false; + EyePictureBox2.Image = Properties.Resources.eye; } else { - button1.Enabled = false; + NewKeyTextBox.UseSystemPasswordChar = true; + EyePictureBox2.Image = Properties.Resources.eye_half; } } + private void OldKeyTextBox_TextChanged(object sender, EventArgs e) + { + if (OldKeyTextBox.Text.Length > 0) + { + AcceptButton.Enabled = true; + } + else + { + AcceptButton.Enabled = false; + } + } + + private void NewKeyTextBox_TextChanged(object sender, EventArgs e) + { + if (NewKeyTextBox.Text.Length > 0) + { + AcceptButton.Enabled = true; + } + else + { + AcceptButton.Enabled = false; + } + } + /*Enter keys area*/ } }