ChangeKeyForm code now is more readable

1) Сode has been divided into blocks and commented.
2) Almost all names now starts from an uppercase.
This commit is contained in:
Alexander 2018-12-25 17:55:15 +02:00
parent 5220065ff0
commit 1febb7e3fa
2 changed files with 170 additions and 172 deletions

View file

@ -28,141 +28,141 @@ protected override void Dispose(bool disposing)
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.textBox1 = new System.Windows.Forms.TextBox(); this.OldKeyTextBox = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox(); this.NewKeyTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label(); this.OldKeyLabel = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.NewKeyLabel = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button(); this.AcceptButton = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox3 = new System.Windows.Forms.PictureBox(); this.KeysPictureBox = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.EyePictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.EyePictureBox1 = new System.Windows.Forms.PictureBox();
this.statusLabel = new System.Windows.Forms.Label(); this.StatusLabel = new System.Windows.Forms.Label();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.KeysPictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// textBox1 // OldKeyTextBox
// //
this.textBox1.Location = new System.Drawing.Point(120, 9); this.OldKeyTextBox.Location = new System.Drawing.Point(120, 9);
this.textBox1.Name = "textBox1"; this.OldKeyTextBox.Name = "OldKeyTextBox";
this.textBox1.Size = new System.Drawing.Size(100, 20); this.OldKeyTextBox.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0; this.OldKeyTextBox.TabIndex = 0;
this.textBox1.UseSystemPasswordChar = true; this.OldKeyTextBox.UseSystemPasswordChar = true;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); this.OldKeyTextBox.TextChanged += new System.EventHandler(this.OldKeyTextBox_TextChanged);
// //
// textBox2 // NewKeyTextBox
// //
this.textBox2.Location = new System.Drawing.Point(120, 43); this.NewKeyTextBox.Location = new System.Drawing.Point(120, 43);
this.textBox2.Name = "textBox2"; this.NewKeyTextBox.Name = "NewKeyTextBox";
this.textBox2.Size = new System.Drawing.Size(100, 20); this.NewKeyTextBox.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 1; this.NewKeyTextBox.TabIndex = 1;
this.textBox2.UseSystemPasswordChar = true; this.NewKeyTextBox.UseSystemPasswordChar = true;
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged); this.NewKeyTextBox.TextChanged += new System.EventHandler(this.NewKeyTextBox_TextChanged);
// //
// label1 // OldKeyLabel
// //
this.label1.AutoSize = true; this.OldKeyLabel.AutoSize = true;
this.label1.Location = new System.Drawing.Point(61, 12); this.OldKeyLabel.Location = new System.Drawing.Point(61, 12);
this.label1.Name = "label1"; this.OldKeyLabel.Name = "OldKeyLabel";
this.label1.Size = new System.Drawing.Size(47, 13); this.OldKeyLabel.Size = new System.Drawing.Size(47, 13);
this.label1.TabIndex = 2; this.OldKeyLabel.TabIndex = 2;
this.label1.Text = "Old Key:"; this.OldKeyLabel.Text = "Old Key:";
// //
// label2 // NewKeyLabel
// //
this.label2.AutoSize = true; this.NewKeyLabel.AutoSize = true;
this.label2.Location = new System.Drawing.Point(61, 46); this.NewKeyLabel.Location = new System.Drawing.Point(61, 46);
this.label2.Name = "label2"; this.NewKeyLabel.Name = "NewKeyLabel";
this.label2.Size = new System.Drawing.Size(53, 13); this.NewKeyLabel.Size = new System.Drawing.Size(53, 13);
this.label2.TabIndex = 3; this.NewKeyLabel.TabIndex = 3;
this.label2.Text = "New Key:"; this.NewKeyLabel.Text = "New Key:";
// //
// button1 // AcceptButton
// //
this.button1.Enabled = false; this.AcceptButton.Enabled = false;
this.button1.Location = new System.Drawing.Point(206, 82); this.AcceptButton.Location = new System.Drawing.Point(206, 82);
this.button1.Name = "button1"; this.AcceptButton.Name = "AcceptButton";
this.button1.Size = new System.Drawing.Size(53, 23); this.AcceptButton.Size = new System.Drawing.Size(53, 23);
this.button1.TabIndex = 4; this.AcceptButton.TabIndex = 4;
this.button1.Text = "Accept"; this.AcceptButton.Text = "Accept";
this.button1.UseVisualStyleBackColor = true; this.AcceptButton.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click); this.AcceptButton.Click += new System.EventHandler(this.AcceptButton_Click);
// //
// panel1 // panel1
// //
this.panel1.BackColor = System.Drawing.Color.White; this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.Controls.Add(this.pictureBox3); this.panel1.Controls.Add(this.KeysPictureBox);
this.panel1.Controls.Add(this.pictureBox2); this.panel1.Controls.Add(this.EyePictureBox2);
this.panel1.Controls.Add(this.label1); this.panel1.Controls.Add(this.OldKeyLabel);
this.panel1.Controls.Add(this.pictureBox1); this.panel1.Controls.Add(this.EyePictureBox1);
this.panel1.Controls.Add(this.textBox1); this.panel1.Controls.Add(this.OldKeyTextBox);
this.panel1.Controls.Add(this.textBox2); this.panel1.Controls.Add(this.NewKeyTextBox);
this.panel1.Controls.Add(this.label2); this.panel1.Controls.Add(this.NewKeyLabel);
this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1"; this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(262, 75); this.panel1.Size = new System.Drawing.Size(262, 75);
this.panel1.TabIndex = 6; this.panel1.TabIndex = 6;
// //
// pictureBox3 // KeysPictureBox
// //
this.pictureBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.KeysPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox3.Image = global::Crypto_Notepad.Properties.Resources.gnupg_keys; this.KeysPictureBox.Image = global::Crypto_Notepad.Properties.Resources.gnupg_keys;
this.pictureBox3.Location = new System.Drawing.Point(8, 12); this.KeysPictureBox.Location = new System.Drawing.Point(8, 12);
this.pictureBox3.Name = "pictureBox3"; this.KeysPictureBox.Name = "KeysPictureBox";
this.pictureBox3.Size = new System.Drawing.Size(47, 47); this.KeysPictureBox.Size = new System.Drawing.Size(47, 47);
this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.KeysPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox3.TabIndex = 7; this.KeysPictureBox.TabIndex = 7;
this.pictureBox3.TabStop = false; this.KeysPictureBox.TabStop = false;
// //
// pictureBox2 // EyePictureBox2
// //
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.EyePictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox2.Cursor = System.Windows.Forms.Cursors.Hand; this.EyePictureBox2.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox2.Image = global::Crypto_Notepad.Properties.Resources.eye_half; this.EyePictureBox2.Image = global::Crypto_Notepad.Properties.Resources.eye_half;
this.pictureBox2.Location = new System.Drawing.Point(219, 43); this.EyePictureBox2.Location = new System.Drawing.Point(219, 43);
this.pictureBox2.Name = "pictureBox2"; this.EyePictureBox2.Name = "EyePictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(32, 20); this.EyePictureBox2.Size = new System.Drawing.Size(32, 20);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.EyePictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox2.TabIndex = 5; this.EyePictureBox2.TabIndex = 5;
this.pictureBox2.TabStop = false; this.EyePictureBox2.TabStop = false;
this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click); this.EyePictureBox2.Click += new System.EventHandler(this.EyePictureBox2_Click);
// //
// pictureBox1 // EyePictureBox1
// //
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.EyePictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand; this.EyePictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox1.Image = global::Crypto_Notepad.Properties.Resources.eye_half; this.EyePictureBox1.Image = global::Crypto_Notepad.Properties.Resources.eye_half;
this.pictureBox1.Location = new System.Drawing.Point(219, 9); this.EyePictureBox1.Location = new System.Drawing.Point(219, 9);
this.pictureBox1.Name = "pictureBox1"; this.EyePictureBox1.Name = "EyePictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(32, 20); this.EyePictureBox1.Size = new System.Drawing.Size(32, 20);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.EyePictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 5; this.EyePictureBox1.TabIndex = 5;
this.pictureBox1.TabStop = false; this.EyePictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); this.EyePictureBox1.Click += new System.EventHandler(this.EyePictureBox1_Click);
// //
// statusLabel // StatusLabel
// //
this.statusLabel.AutoSize = true; 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.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.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.Location = new System.Drawing.Point(5, 87);
this.statusLabel.Name = "statusLabel"; this.StatusLabel.Name = "StatusLabel";
this.statusLabel.Size = new System.Drawing.Size(43, 16); this.StatusLabel.Size = new System.Drawing.Size(43, 16);
this.statusLabel.TabIndex = 7; this.StatusLabel.TabIndex = 7;
this.statusLabel.Text = "status"; this.StatusLabel.Text = "status";
this.statusLabel.Visible = false; this.StatusLabel.Visible = false;
// //
// ChangeKeyForm // ChangeKeyForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(263, 111); 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.panel1);
this.Controls.Add(this.button1); this.Controls.Add(this.AcceptButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
@ -171,9 +171,9 @@ private void InitializeComponent()
this.Text = "Change Key"; this.Text = "Change Key";
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.panel1.PerformLayout(); this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.KeysPictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.EyePictureBox1)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -181,15 +181,15 @@ private void InitializeComponent()
#endregion #endregion
private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox OldKeyTextBox;
private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox NewKeyTextBox;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label OldKeyLabel;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label NewKeyLabel;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button AcceptButton;
private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox EyePictureBox1;
private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.PictureBox EyePictureBox2;
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.PictureBox pictureBox3; private System.Windows.Forms.PictureBox KeysPictureBox;
private System.Windows.Forms.Label statusLabel; private System.Windows.Forms.Label StatusLabel;
} }
} }

View file

@ -12,100 +12,98 @@ public ChangeKeyForm()
InitializeComponent(); 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; PublicVar.keyChanged = true;
textBox1.Text = ""; OldKeyTextBox.Text = "";
textBox2.Text = ""; NewKeyTextBox.Text = "";
statusLabel.Text = "Key was successfully changed"; StatusLabel.Text = "Key was successfully changed";
statusLabel.Visible = true; StatusLabel.Visible = true;
button1.Enabled = false; AcceptButton.Enabled = false;
await Task.Delay(2000); await Task.Delay(2000);
statusLabel.Text = ""; StatusLabel.Text = "";
return; return;
} }
if (textBox1.Text != PublicVar.encryptionKey.Get()) if (OldKeyTextBox.Text != PublicVar.encryptionKey.Get())
{ {
SystemSounds.Beep.Play(); SystemSounds.Beep.Play();
statusLabel.Text = "Invalid old key"; StatusLabel.Text = "Invalid old key";
statusLabel.Visible = true; StatusLabel.Visible = true;
textBox1.Text = ""; OldKeyTextBox.Text = "";
textBox2.Text = ""; NewKeyTextBox.Text = "";
return; return;
} }
if (textBox1.Text == textBox2.Text) if (OldKeyTextBox.Text == NewKeyTextBox.Text)
{ {
SystemSounds.Beep.Play(); SystemSounds.Beep.Play();
statusLabel.Text = "New key is the same as old"; StatusLabel.Text = "New key is the same as old";
statusLabel.Visible = true; StatusLabel.Visible = true;
textBox1.Text = ""; OldKeyTextBox.Text = "";
textBox2.Text = ""; NewKeyTextBox.Text = "";
return; 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; OldKeyTextBox.UseSystemPasswordChar = false;
pictureBox1.Image = Properties.Resources.eye; EyePictureBox1.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;
} }
else 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 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*/
} }
} }