ShareX/HelpersLib/Forms/InputBox.cs

159 lines
5.9 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
2014-05-13 21:06:40 +12:00
Copyright (C) 2007-2014 ShareX Developers
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;
using System.Windows.Forms;
namespace HelpersLib
{
public class InputBox : Form
{
2014-06-21 00:05:04 +12:00
public string Title { get; set; }
2013-11-03 23:53:49 +13:00
public string InputText { get; set; }
2014-06-21 00:05:04 +12:00
public InputBox(string title = null, string inputText = null)
2013-11-03 23:53:49 +13:00
{
InitializeComponent();
2014-06-21 00:05:04 +12:00
Icon = ShareXResources.Icon;
2013-11-03 23:53:49 +13:00
2014-06-21 00:05:04 +12:00
Title = title;
2013-11-03 23:53:49 +13:00
InputText = inputText;
2014-06-21 00:05:04 +12:00
if (!string.IsNullOrEmpty(Title)) Text = Title;
if (!string.IsNullOrEmpty(InputText)) txtInputText.Text = InputText;
2013-11-03 23:53:49 +13:00
}
private void InputBox_Shown(object sender, EventArgs e)
{
this.ShowActivate();
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;
DialogResult = DialogResult.OK;
2013-11-03 23:53:49 +13:00
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
2014-06-21 00:05:04 +12:00
public static string GetInputText(string title = null, string inputText = null)
2013-11-03 23:53:49 +13:00
{
2014-06-21 00:05:04 +12:00
using (InputBox form = new InputBox(title, inputText))
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()
{
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.txtInputText = new System.Windows.Forms.TextBox();
this.SuspendLayout();
2014-07-29 19:47:43 +12:00
//
2013-11-03 23:53:49 +13:00
// btnOK
2014-07-29 19:47:43 +12:00
//
2014-06-21 00:05:04 +12:00
this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnOK.Location = new System.Drawing.Point(208, 32);
2013-11-03 23:53:49 +13:00
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(72, 24);
2014-06-21 00:05:04 +12:00
this.btnOK.TabIndex = 1;
2013-11-03 23:53:49 +13:00
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
2014-07-29 19:47:43 +12:00
//
2013-11-03 23:53:49 +13:00
// btnCancel
2014-07-29 19:47:43 +12:00
//
2014-06-21 00:05:04 +12:00
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.Location = new System.Drawing.Point(288, 32);
2013-11-03 23:53:49 +13:00
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(72, 24);
2014-06-21 00:05:04 +12:00
this.btnCancel.TabIndex = 2;
2013-11-03 23:53:49 +13:00
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
2014-07-29 19:47:43 +12:00
//
2013-11-03 23:53:49 +13:00
// txtInputText
2014-07-29 19:47:43 +12:00
//
this.txtInputText.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
2014-06-21 00:05:04 +12:00
| System.Windows.Forms.AnchorStyles.Right)));
this.txtInputText.Location = new System.Drawing.Point(8, 8);
2013-11-03 23:53:49 +13:00
this.txtInputText.Name = "txtInputText";
this.txtInputText.Size = new System.Drawing.Size(352, 20);
2014-06-21 00:05:04 +12:00
this.txtInputText.TabIndex = 0;
2014-07-29 19:47:43 +12:00
//
2013-11-03 23:53:49 +13:00
// InputBox
2014-07-29 19:47:43 +12:00
//
2013-11-03 23:53:49 +13:00
this.AcceptButton = this.btnOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
2014-06-21 00:05:04 +12:00
this.ClientSize = new System.Drawing.Size(368, 64);
2013-11-03 23:53:49 +13:00
this.Controls.Add(this.txtInputText);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.MaximizeBox = false;
2014-07-05 02:23:53 +12:00
this.MaximumSize = new System.Drawing.Size(1000, 102);
2013-11-03 23:53:49 +13:00
this.MinimizeBox = false;
2014-07-05 02:23:53 +12:00
this.MinimumSize = new System.Drawing.Size(384, 102);
2013-11-03 23:53:49 +13:00
this.Name = "InputBox";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
2014-06-21 00:05:04 +12:00
this.Text = "ShareX - Input box";
2013-11-03 23:53:49 +13:00
this.TopMost = true;
this.Shown += new System.EventHandler(this.InputBox_Shown);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox txtInputText;
#endregion Windows Form Designer generated code
}
}