This repository has been archived on 2022-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
bookmark-manager/RyzStudio/Windows/ThemedForms/TextBoxForm.cs

99 lines
2.6 KiB
C#
Raw Permalink Normal View History

2019-04-21 17:53:56 +00:00
using System;
using System.ComponentModel;
2019-04-21 17:53:56 +00:00
using System.Windows.Forms;
namespace RyzStudio.Windows.ThemedForms
{
2019-04-22 11:40:29 +00:00
public partial class TextBoxForm : System.Windows.Forms.Form
2019-04-21 17:53:56 +00:00
{
protected bool returnValue = false;
2019-04-21 17:53:56 +00:00
public TextBoxForm(string title, string labelText, string defaultValue)
{
InitializeComponent();
2019-04-22 14:51:03 +00:00
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
2019-04-21 17:53:56 +00:00
this.Text = title;
label2.Text = labelText;
textBox1.Text = defaultValue;
}
public TextBoxForm(string title, string labelText, string defaultValue, bool password)
{
InitializeComponent();
2019-04-22 14:51:03 +00:00
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
2019-04-21 17:53:56 +00:00
this.Text = title;
label2.Text = labelText;
textBox1.Text = defaultValue;
textBox1.UseSystemPasswordChar = password;
2019-04-22 14:51:03 +00:00
2019-04-21 17:53:56 +00:00
}
public TextBoxForm(string title, string labelText)
{
InitializeComponent();
2019-04-22 14:51:03 +00:00
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
2019-04-21 17:53:56 +00:00
this.Text = title;
label2.Text = labelText;
}
public TextBoxForm(string title, string labelText, bool password)
{
InitializeComponent();
2019-04-22 14:51:03 +00:00
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
2019-04-21 17:53:56 +00:00
this.Text = title;
label2.Text = labelText;
textBox1.UseSystemPasswordChar = password;
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
if (!returnValue)
{
textBox1.Text = string.Empty;
}
}
2019-04-21 17:53:56 +00:00
private void button2_Click(object sender, EventArgs e)
{
returnValue = true;
2019-04-21 17:53:56 +00:00
this.Close();
}
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
2019-04-23 19:15:17 +00:00
textBox1.Text = string.Empty;
2019-04-21 17:53:56 +00:00
this.Close();
break;
default: break;
}
}
public new string ShowDialog()
{
returnValue = false;
2019-04-21 17:53:56 +00:00
base.ShowDialog();
return textBox1.Text;
}
2019-04-21 17:53:56 +00:00
}
}