ShareX/ShareX.HelpersLib/Forms/InputBox.cs

151 lines
5.2 KiB
C#
Raw Normal View History

2013-11-03 23:53:49 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2022-01-12 05:32:17 +13:00
Copyright (c) 2007-2022 ShareX Team
2013-11-03 23:53:49 +13:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using System;
2018-04-16 11:40:58 +12:00
using System.Drawing;
2013-11-03 23:53:49 +13:00
using System.Windows.Forms;
2014-12-11 09:25:20 +13:00
namespace ShareX.HelpersLib
2013-11-03 23:53:49 +13:00
{
public class InputBox : Form
2013-11-03 23:53:49 +13:00
{
public string InputText { get; private set; }
2013-11-03 23:53:49 +13:00
public InputBox(string title = null, string inputText = null, string okText = null, string cancelText = null)
2013-11-03 23:53:49 +13:00
{
InitializeComponent();
2019-06-25 06:36:16 +12:00
ShareXResources.ApplyTheme(this);
2013-11-03 23:53:49 +13:00
InputText = inputText;
if (!string.IsNullOrEmpty(title)) Text = title;
2014-06-21 00:05:04 +12:00
if (!string.IsNullOrEmpty(InputText)) txtInputText.Text = InputText;
if (!string.IsNullOrEmpty(okText)) btnOK.Text = okText;
if (!string.IsNullOrEmpty(cancelText)) btnCancel.Text = cancelText;
2013-11-03 23:53:49 +13:00
}
private void InputBox_Shown(object sender, EventArgs e)
{
this.ForceActivate();
2018-10-10 00:30:22 +13:00
MinimumSize = new Size(384, Size.Height);
MaximumSize = new Size(1000, Size.Height);
2013-11-03 23:53:49 +13:00
txtInputText.SelectionLength = txtInputText.Text.Length;
}
private void btnOK_Click(object sender, EventArgs e)
{
2014-06-21 00:05:04 +12:00
InputText = txtInputText.Text;
2014-06-21 00:05:04 +12:00
DialogResult = DialogResult.OK;
Close();
2013-11-03 23:53:49 +13:00
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
2013-11-03 23:53:49 +13:00
}
public static string GetInputText(string title = null, string inputText = null, string okText = null, string cancelText = null)
2013-11-03 23:53:49 +13:00
{
using (InputBox form = new InputBox(title, inputText, okText, cancelText))
2013-11-03 23:53:49 +13:00
{
if (form.ShowDialog() == DialogResult.OK)
{
return form.InputText;
}
return null;
}
}
#region Windows Form Designer generated code
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InputBox));
2018-10-10 00:30:22 +13:00
btnOK = new System.Windows.Forms.Button();
btnCancel = new System.Windows.Forms.Button();
txtInputText = new System.Windows.Forms.TextBox();
SuspendLayout();
//
2013-11-03 23:53:49 +13:00
// btnOK
//
2018-10-10 00:30:22 +13:00
resources.ApplyResources(btnOK, "btnOK");
btnOK.Name = "btnOK";
btnOK.UseVisualStyleBackColor = true;
btnOK.Click += new System.EventHandler(btnOK_Click);
//
2013-11-03 23:53:49 +13:00
// btnCancel
//
2018-10-10 00:30:22 +13:00
resources.ApplyResources(btnCancel, "btnCancel");
btnCancel.Name = "btnCancel";
btnCancel.UseVisualStyleBackColor = true;
btnCancel.Click += new System.EventHandler(btnCancel_Click);
//
2013-11-03 23:53:49 +13:00
// txtInputText
//
2018-10-10 00:30:22 +13:00
resources.ApplyResources(txtInputText, "txtInputText");
txtInputText.Name = "txtInputText";
//
2013-11-03 23:53:49 +13:00
// InputBox
//
2018-10-10 00:30:22 +13:00
AcceptButton = btnOK;
resources.ApplyResources(this, "$this");
2018-10-10 00:30:22 +13:00
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
BackColor = System.Drawing.SystemColors.Window;
Controls.Add(txtInputText);
Controls.Add(btnCancel);
Controls.Add(btnOK);
MaximizeBox = false;
MinimizeBox = false;
Name = "InputBox";
ShowInTaskbar = false;
SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
TopMost = true;
Shown += new System.EventHandler(InputBox_Shown);
ResumeLayout(false);
PerformLayout();
2013-11-03 23:53:49 +13:00
}
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox txtInputText;
#endregion Windows Form Designer generated code
}
}