Crypto-Notepad/Crypto Notepad/Forms/EnterPasswordForm.cs

113 lines
3.1 KiB
C#
Raw Permalink Normal View History

using System;
2016-01-06 14:47:38 +00:00
using System.Windows.Forms;
2016-01-09 20:46:25 +00:00
namespace Crypto_Notepad
2016-01-06 14:47:38 +00:00
{
public partial class EnterPasswordForm : Form
2016-01-06 14:47:38 +00:00
{
public EnterPasswordForm()
2016-01-06 14:47:38 +00:00
{
2018-12-17 11:04:26 +00:00
PublicVar.okPressed = false;
2016-01-06 14:47:38 +00:00
InitializeComponent();
}
/*Form Events*/
private void EnterPasswordForm_FormClosed(object sender, FormClosedEventArgs e)
2016-01-06 14:47:38 +00:00
{
2019-09-28 19:57:03 +00:00
MainForm main = Owner as MainForm;
if (main.Visible == false)
{
2019-10-13 11:54:45 +00:00
main.trayIcon.Visible = false;
2019-10-11 10:39:15 +00:00
Environment.Exit(0);
2019-09-28 19:57:03 +00:00
}
2019-10-13 11:54:45 +00:00
keyTextBox.Focus();
2016-01-06 14:47:38 +00:00
}
private void EnterPasswordForm_Load(object sender, EventArgs e)
{
2019-10-13 11:54:45 +00:00
fileNameLabel.Text = PublicVar.openFileName;
2019-10-11 10:39:15 +00:00
Properties.Settings settings = Properties.Settings.Default;
TopMost = settings.alwaysOnTop;
MainForm main = Owner as MainForm;
if (main.Visible)
{
CenterToParent();
}
else
{
CenterToScreen();
}
}
private void EnterPasswordForm_Shown(object sender, EventArgs e)
{
fileNameLabel.Text = PublicVar.openFileName;
}
/*Form Events*/
/*Enter key area*/
2019-10-13 11:54:45 +00:00
private void KeyTextBox_TextChanged(object sender, EventArgs e)
2016-01-06 14:47:38 +00:00
{
2019-10-13 11:55:20 +00:00
if (keyTextBox.Text.Length > 0)
{
okButton.Enabled = true;
}
2016-01-06 14:47:38 +00:00
else
2019-10-13 11:55:20 +00:00
{
okButton.Enabled = false;
}
2016-01-06 14:47:38 +00:00
}
2019-10-13 11:54:45 +00:00
private void KeyTextBox_KeyDown(object sender, KeyEventArgs e)
2016-01-06 14:47:38 +00:00
{
2019-10-15 16:13:08 +00:00
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
}
if (e.KeyCode == Keys.Enter & okButton.Enabled)
2016-01-06 14:47:38 +00:00
{
2019-10-13 11:54:45 +00:00
OkButton_Click(sender, e);
2016-01-06 14:47:38 +00:00
}
}
2019-10-13 11:54:45 +00:00
private void ShowKeyPictureBox_Click(object sender, EventArgs e)
2016-01-06 14:47:38 +00:00
{
2019-10-13 11:54:45 +00:00
if (keyTextBox.UseSystemPasswordChar)
2016-01-06 14:47:38 +00:00
{
2019-10-13 11:54:45 +00:00
keyTextBox.UseSystemPasswordChar = false;
showKeyPictureBox.Image = Properties.Resources.eye;
2016-01-06 14:47:38 +00:00
}
else
2016-01-06 14:47:38 +00:00
{
2019-10-13 11:54:45 +00:00
keyTextBox.UseSystemPasswordChar = true;
showKeyPictureBox.Image = Properties.Resources.eye_half;
2016-01-06 14:47:38 +00:00
}
}
/*Enter key area*/
2016-01-09 19:29:13 +00:00
/*Buttons*/
2019-10-13 11:54:45 +00:00
private void OkButton_Click(object sender, EventArgs e)
2017-02-05 20:47:31 +00:00
{
2019-10-13 11:54:45 +00:00
TypedPassword.Value = keyTextBox.Text;
keyTextBox.Focus();
PublicVar.okPressed = true;
2019-10-15 16:09:51 +00:00
Hide();
2017-02-05 20:47:31 +00:00
}
2019-11-11 17:19:29 +00:00
private void PasswordGeneratorButton_Click(object sender, EventArgs e)
{
ActiveControl = null;
PasswordGeneratorFrom passwordGeneratorFrom = new PasswordGeneratorFrom();
if ((Application.OpenForms["PasswordGeneratorFrom"] as PasswordGeneratorFrom) == null)
{
passwordGeneratorFrom.Show(this);
}
}
/*Buttons*/
2019-09-28 19:57:03 +00:00
2016-01-06 14:47:38 +00:00
}
}