using System;
using System.Drawing;
using System.Windows.Forms;

namespace Gsome
{
	public static class InputBox
	{
		public static DialogResult Show(Form owner, string caption, ref string value)
		{
			InputBox.dlgForm dlgForm = new InputBox.dlgForm();
			dlgForm.Text = caption;
			dlgForm.txtInput.Text = value;
			DialogResult dialogResult = dlgForm.ShowDialog(owner);
			if (dialogResult == DialogResult.OK)
			{
				value = dlgForm.txtInput.Text;
			}
			dlgForm.Dispose();
			return dialogResult;
		}

		private class dlgForm : Form
		{
			private void btnOk_Click(object sender, EventArgs e)
			{
				base.DialogResult = DialogResult.OK;
			}

			protected override void Dispose(bool disposing)
			{
				if (disposing)
				{
					this.pnlLayout.Dispose();
					this.btnCancel.Dispose();
					this.btnOk.Dispose();
					this.txtInput.Dispose();
				}
				base.Dispose(disposing);
			}

			public dlgForm()
			{
				this.pnlLayout = new TableLayoutPanel();
				this.btnOk = new Button();
				this.btnCancel = new Button();
				this.txtInput = new TextBox();
				this.pnlLayout.ColumnCount = 2;
				this.pnlLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f));
				this.pnlLayout.ColumnStyles.Add(new ColumnStyle());
				this.pnlLayout.Controls.Add(this.btnOk, 0, 1);
				this.pnlLayout.Controls.Add(this.btnCancel, 1, 1);
				this.pnlLayout.Controls.Add(this.txtInput, 0, 0);
				this.pnlLayout.Dock = DockStyle.Fill;
				this.pnlLayout.RowCount = 2;
				this.pnlLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100f));
				this.pnlLayout.RowStyles.Add(new RowStyle());
				this.pnlLayout.Size = new Size(415, 66);
				this.pnlLayout.TabIndex = 0;
				this.btnOk.Anchor = AnchorStyles.Right;
				this.btnOk.Size = new Size(100, 25);
				this.btnOk.TabIndex = 1;
				this.btnOk.Text = "OK";
				this.btnOk.Click += this.btnOk_Click;
				this.btnCancel.Anchor = AnchorStyles.Right;
				this.btnCancel.DialogResult = DialogResult.Cancel;
				this.btnCancel.Size = new Size(100, 25);
				this.btnCancel.TabIndex = 2;
				this.btnCancel.Text = "Отмена";
				this.txtInput.Anchor = (AnchorStyles.Left | AnchorStyles.Right);
				this.pnlLayout.SetColumnSpan(this.txtInput, 2);
				this.txtInput.TabIndex = 0;
				base.AcceptButton = this.btnOk;
				base.CancelButton = this.btnCancel;
				base.ClientSize = new Size(240, 100);
				base.Controls.Add(this.pnlLayout);
				base.MaximizeBox = false;
				this.MaximumSize = new Size(10000, 100);
				base.MinimizeBox = false;
				this.MinimumSize = new Size(250, 100);
				base.ShowIcon = false;
				base.ShowInTaskbar = false;
				base.StartPosition = FormStartPosition.CenterParent;
			}

			private TableLayoutPanel pnlLayout;

			private Button btnCancel;

			private Button btnOk;

			public TextBox txtInput;
		}
	}
}
