Fixed issue with "Enter Key" form

This commit is contained in:
Sigmanor 2016-01-09 21:29:13 +02:00
parent 06abd965e9
commit c2fa34cdb4
4 changed files with 150 additions and 81 deletions

View file

@ -84,17 +84,17 @@ public void InitializeComponent()
this.lineStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.lineStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.columnStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.columnStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.searchTextBox = new System.Windows.Forms.TextBox(); this.searchTextBox = new System.Windows.Forms.TextBox();
this.chkMatchCase = new System.Windows.Forms.CheckBox(); this.chkMatchCase = new System.Windows.Forms.CheckBox();
this.chkMatchWholeWord = new System.Windows.Forms.CheckBox(); this.chkMatchWholeWord = new System.Windows.Forms.CheckBox();
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.customRTB = new EncryptPad.CustomRichTextBox(); this.customRTB = new EncryptPad.CustomRichTextBox();
this.MainMenu.SuspendLayout(); this.MainMenu.SuspendLayout();
this.contextMenuStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// MainMenu // MainMenu
@ -332,14 +332,14 @@ public void InitializeComponent()
// changeKeyToolStripMenuItem // changeKeyToolStripMenuItem
// //
this.changeKeyToolStripMenuItem.Name = "changeKeyToolStripMenuItem"; this.changeKeyToolStripMenuItem.Name = "changeKeyToolStripMenuItem";
this.changeKeyToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.changeKeyToolStripMenuItem.Size = new System.Drawing.Size(139, 22);
this.changeKeyToolStripMenuItem.Text = "Change Key"; this.changeKeyToolStripMenuItem.Text = "Change Key";
this.changeKeyToolStripMenuItem.Click += new System.EventHandler(this.changeKeyToolStripMenuItem_Click); this.changeKeyToolStripMenuItem.Click += new System.EventHandler(this.changeKeyToolStripMenuItem_Click);
// //
// settingsToolStripMenuItem // settingsToolStripMenuItem
// //
this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
this.settingsToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.settingsToolStripMenuItem.Size = new System.Drawing.Size(139, 22);
this.settingsToolStripMenuItem.Text = "Settings"; this.settingsToolStripMenuItem.Text = "Settings";
this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click); this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click);
// //
@ -355,7 +355,6 @@ public void InitializeComponent()
// //
// documentationToolStripMenuItem // documentationToolStripMenuItem
// //
this.documentationToolStripMenuItem.Enabled = false;
this.documentationToolStripMenuItem.Name = "documentationToolStripMenuItem"; this.documentationToolStripMenuItem.Name = "documentationToolStripMenuItem";
this.documentationToolStripMenuItem.Size = new System.Drawing.Size(189, 22); this.documentationToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
this.documentationToolStripMenuItem.Text = "Documentation"; this.documentationToolStripMenuItem.Text = "Documentation";
@ -534,6 +533,20 @@ public void InitializeComponent()
this.columnStripStatusLabel.Size = new System.Drawing.Size(56, 17); this.columnStripStatusLabel.Size = new System.Drawing.Size(56, 17);
this.columnStripStatusLabel.Text = "Column:"; this.columnStripStatusLabel.Text = "Column:";
// //
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(670, 7);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(14, 14);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 14;
this.pictureBox1.TabStop = false;
this.toolTip1.SetToolTip(this.pictureBox1, "Close");
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// searchTextBox // searchTextBox
// //
this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -585,20 +598,6 @@ public void InitializeComponent()
this.panel1.TabIndex = 13; this.panel1.TabIndex = 13;
this.panel1.Visible = false; this.panel1.Visible = false;
// //
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(670, 7);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(14, 14);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 14;
this.pictureBox1.TabStop = false;
this.toolTip1.SetToolTip(this.pictureBox1, "Close");
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// customRTB // customRTB
// //
this.customRTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.customRTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -643,9 +642,9 @@ public void InitializeComponent()
this.contextMenuStrip1.ResumeLayout(false); this.contextMenuStrip1.ResumeLayout(false);
this.statusStrip1.ResumeLayout(false); this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout(); this.statusStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.panel1.PerformLayout(); this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View file

@ -17,6 +17,8 @@ public partial class MainWindow : Form
static extern int SendMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam); static extern int SendMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam);
public static string filename = "Unnamed.enp"; public static string filename = "Unnamed.enp";
public static string key = ""; public static string key = "";
public static bool keyChanged = false;
public static bool settingsChanged = false;
public static int textSave = 0; public static int textSave = 0;
public static string[] args = Environment.GetCommandLineArgs(); public static string[] args = Environment.GetCommandLineArgs();
Properties.Settings ps = Properties.Settings.Default; Properties.Settings ps = Properties.Settings.Default;
@ -38,9 +40,11 @@ void SaltMAC()
if (ps.FirstLaunch == false) if (ps.FirstLaunch == false)
{ {
DialogResult res = new DialogResult(); DialogResult res = new DialogResult();
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this); using (new CenterWinDialog(this))
res = MessageBox.Show("Get The Salt from mac address? (You can edit it by himself in Settings)", "The Salt", {
MessageBoxButtons.YesNo, MessageBoxIcon.Question); res = MessageBox.Show("Get The Salt from mac address? (You can edit it by himself in Settings)", "The Salt",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
if (res == DialogResult.Yes) if (res == DialogResult.Yes)
{ {
@ -57,18 +61,19 @@ void SaltMAC()
private void открытьToolStripMenuItem_Click(object sender, EventArgs e) private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
{ {
int Cikil = 0; int Cikil = 0;
Form2 f2 = new Form2();
try try
{ {
if (OpenFile.ShowDialog() != DialogResult.OK) return; if (OpenFile.ShowDialog() != DialogResult.OK) return;
{ {
string NameWithotPath = Path.GetFileName(OpenFile.FileName); string NameWithotPath = Path.GetFileName(OpenFile.FileName);
string opnfile = File.ReadAllText(OpenFile.FileName); string opnfile = File.ReadAllText(OpenFile.FileName);
Form2 f2 = new Form2();
f2.ShowDialog(); f2.ShowDialog();
if (Form2.formClosing == true) if (Form2.OkPressed == false)
{ {
return; return;
} }
Form2.OkPressed = false;
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize); string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
@ -89,31 +94,39 @@ void SaltMAC()
{ {
Cikil = 0; Cikil = 0;
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this); using (new CenterWinDialog(this))
DialogResult dialogResult = MessageBox.Show("Wrong key!", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dialogResult == DialogResult.Retry)
{ {
Form2 Form2 = new Form2(); DialogResult dialogResult = MessageBox.Show("Wrong key!", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
Form2.ShowDialog(); if (dialogResult == DialogResult.Retry)
try
{ {
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize); f2.ShowDialog();
if (Form2.OkPressed == false)
{
return;
}
Form2.OkPressed = false;
try
{
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
customRTB.Text = de;
toolStripStatusLabel1.Text = NameWithotPath;
toolStripStatusLabel1.ToolTipText = (OpenFile.FileName);
}
catch
{
Cikil = 1;
}
customRTB.Text = de;
toolStripStatusLabel1.Text = NameWithotPath;
toolStripStatusLabel1.ToolTipText = (OpenFile.FileName);
} }
catch
if (dialogResult == DialogResult.Cancel)
{ {
Cikil = 1; toolStripStatusLabel1.Text = "Ready";
} }
} }
if (dialogResult == DialogResult.Cancel)
{
toolStripStatusLabel1.Text = "Ready";
}
} while (Cikil == 1); } while (Cikil == 1);
filename = OpenFile.FileName; filename = OpenFile.FileName;
@ -139,10 +152,11 @@ private void openAsotiations()
string NameWithotPath = Path.GetFileName(args[1]); string NameWithotPath = Path.GetFileName(args[1]);
string opnfile = File.ReadAllText(args[1]); string opnfile = File.ReadAllText(args[1]);
Form2.ShowDialog(); Form2.ShowDialog();
if (Form2.formClosing == true) if (Form2.OkPressed == false)
{ {
return; return;
} }
Form2.OkPressed = false;
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize); string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
customRTB.Text = de; customRTB.Text = de;
@ -160,7 +174,14 @@ private void openAsotiations()
DialogResult dialogResult = MessageBox.Show("Wrong key!", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); DialogResult dialogResult = MessageBox.Show("Wrong key!", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dialogResult == DialogResult.Retry) if (dialogResult == DialogResult.Retry)
{ {
Form2.OkPressed = false;
Form2.ShowDialog(); Form2.ShowDialog();
if (Form2.OkPressed == false)
{
return;
}
Form2.OkPressed = false;
try try
{ {
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize); string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
@ -190,16 +211,29 @@ private void openAsotiations()
private void новыйToolStripMenuItem_Click_1(object sender, EventArgs e) private void новыйToolStripMenuItem_Click_1(object sender, EventArgs e)
{ {
customRTB.Clear(); Form2 f2 = new Form2();
Form2 Form2 = new Form2(); f2.ShowDialog();
Form2.ShowDialog();
if (SaveFile.ShowDialog() != DialogResult.OK) return; if (Form2.OkPressed == false)
StreamWriter sw = new StreamWriter(SaveFile.FileName); {
string NameWithotPath = Path.GetFileName(SaveFile.FileName); return;
toolStripStatusLabel1.Text = NameWithotPath; }
toolStripStatusLabel1.ToolTipText = (SaveFile.FileName);
filename = SaveFile.FileName; if (Form2.OkPressed == true)
sw.Close(); {
Form2.OkPressed = false;
if (SaveFile.ShowDialog() != DialogResult.OK)
{
return;
}
customRTB.Clear();
StreamWriter sw = new StreamWriter(SaveFile.FileName);
string NameWithotPath = Path.GetFileName(SaveFile.FileName);
toolStripStatusLabel1.Text = NameWithotPath;
toolStripStatusLabel1.ToolTipText = (SaveFile.FileName);
filename = SaveFile.FileName;
sw.Close();
}
} }
private async void сохранитьToolStripMenuItem_Click(object sender, EventArgs e) private async void сохранитьToolStripMenuItem_Click(object sender, EventArgs e)
@ -252,8 +286,9 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
if (customRTB.Text != "") if (customRTB.Text != "")
{ {
DialogResult res = new DialogResult(); DialogResult res = new DialogResult();
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this); using (new CenterWinDialog(this))
res = MessageBox.Show("Save changes in:\n" + filename + " ?", {
res = MessageBox.Show("Save changes in:\n" + filename + " ?",
"", "",
MessageBoxButtons.YesNoCancel, MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question); MessageBoxIcon.Question);
@ -274,24 +309,24 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
try try
{ {
if (res == DialogResult.No) if (res == DialogResult.No)
{ {
Environment.Exit(0); Environment.Exit(0);
} }
if (res == DialogResult.Cancel) if (res == DialogResult.Cancel)
{ {
e.Cancel = true; e.Cancel = true;
} }
} }
catch (Exception) catch (Exception)
{ {
} }
}
} }
} }
} }
@ -426,18 +461,22 @@ private void MainWindow_Load(object sender, EventArgs e)
{ {
if (filename != "Unnamed.enp") if (filename != "Unnamed.enp")
{ {
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this); using (new CenterWinDialog(this))
if (MessageBox.Show("Delete file: " + filename + " ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
File.Delete(filename); if (MessageBox.Show("Delete file: " + filename + " ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
toolStripStatusLabel1.Text = filename + " deleted"; {
customRTB.Clear(); File.Delete(filename);
toolStripStatusLabel1.Text = filename + " deleted";
customRTB.Clear();
}
} }
} }
if (filename == "Unnamed.enp") if (filename == "Unnamed.enp")
{ {
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this); using (new CenterWinDialog(this))
MessageBox.Show("No open files", "", MessageBoxButtons.OK, MessageBoxIcon.Question); {
MessageBox.Show("No open files", "", MessageBoxButtons.OK, MessageBoxIcon.Question);
}
} }
} }
@ -449,10 +488,11 @@ private void MainWindow_Load(object sender, EventArgs e)
} }
if (filename == "Unnamed.enp") if (filename == "Unnamed.enp")
{ {
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this); using (new CenterWinDialog(this))
MessageBox.Show("No open files", "", MessageBoxButtons.OK, MessageBoxIcon.Question); {
MessageBox.Show("No open files", "", MessageBoxButtons.OK, MessageBoxIcon.Question);
}
} }
} }
private void переносПоСловамToolStripMenuItem_Click(object sender, EventArgs e) private void переносПоСловамToolStripMenuItem_Click(object sender, EventArgs e)
@ -609,11 +649,21 @@ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
sf.ShowDialog(this); sf.ShowDialog(this);
} }
private void MainWindow_Activated(object sender, EventArgs e) private async void MainWindow_Activated(object sender, EventArgs e)
{ {
customRTB.Font = new Font(ps.RichTextFont, ps.RichTextSize); if (settingsChanged == true)
customRTB.ForeColor = ps.RichForeColor; {
customRTB.BackColor = ps.RichBackColor; customRTB.Font = new Font(ps.RichTextFont, ps.RichTextSize);
customRTB.ForeColor = ps.RichForeColor;
customRTB.BackColor = ps.RichBackColor;
}
if (keyChanged == true)
{
toolStripStatusLabel1.Text = "Key was changed";
await Task.Delay(4000);
toolStripStatusLabel1.Text = "Ready";
}
} }
private void chkMatchCase_CheckedChanged(object sender, EventArgs e) private void chkMatchCase_CheckedChanged(object sender, EventArgs e)

View file

@ -85,6 +85,9 @@ private void InitializeComponent()
this.Name = "Form2"; this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Enter the key"; this.Text = "Enter the key";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_FormClosing);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form2_FormClosed);
this.Load += new System.EventHandler(this.Form2_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View file

@ -5,7 +5,7 @@ namespace EncryptPad
{ {
public partial class Form2 : Form public partial class Form2 : Form
{ {
public static bool formClosing = false; public static bool OkPressed = false;
public Form2() public Form2()
{ {
InitializeComponent(); InitializeComponent();
@ -16,6 +16,7 @@ private void button1_Click(object sender, EventArgs e)
MainWindow.key = textBox1.Text; MainWindow.key = textBox1.Text;
textBox1.Focus(); textBox1.Focus();
textBox1.Text = ""; textBox1.Text = "";
OkPressed = true;
this.Hide(); this.Hide();
} }
@ -49,5 +50,21 @@ private void pictureBox1_Click(object sender, EventArgs e)
return; return;
} }
} }
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
textBox1.Focus();
textBox1.Text = "";
}
private void Form2_Load(object sender, EventArgs e)
{
}
} }
} }