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#

using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace RyzStudio.Windows.ThemedForms
{
public partial class TextBoxForm : System.Windows.Forms.Form
{
protected bool returnValue = false;
public TextBoxForm(string title, string labelText, string defaultValue)
{
InitializeComponent();
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
this.Text = title;
label2.Text = labelText;
textBox1.Text = defaultValue;
}
public TextBoxForm(string title, string labelText, string defaultValue, bool password)
{
InitializeComponent();
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
this.Text = title;
label2.Text = labelText;
textBox1.Text = defaultValue;
textBox1.UseSystemPasswordChar = password;
}
public TextBoxForm(string title, string labelText)
{
InitializeComponent();
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
this.Text = title;
label2.Text = labelText;
}
public TextBoxForm(string title, string labelText, bool password)
{
InitializeComponent();
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
textBox1.InnerTextBox.PreviewKeyDown += textBox1_PreviewKeyDown;
this.Text = title;
label2.Text = labelText;
textBox1.UseSystemPasswordChar = password;
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
if (!returnValue)
{
textBox1.Text = string.Empty;
}
}
private void button2_Click(object sender, EventArgs e)
{
returnValue = true;
this.Close();
}
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
textBox1.Text = string.Empty;
this.Close();
break;
default: break;
}
}
public new string ShowDialog()
{
returnValue = false;
base.ShowDialog();
return textBox1.Text;
}
}
}