00001 using System;
00002 using System.Drawing;
00003 using System.Collections;
00004 using System.ComponentModel;
00005 using System.Windows.Forms;
00006 using System.Data;
00007
00008 namespace sharpSshTest.jsch_samples
00009 {
00013 public class InputForm : System.Windows.Forms.Form
00014 {
00015 private static InputForm inForm;
00016 public System.Windows.Forms.TextBox textBox1;
00017 private System.Windows.Forms.Button btnOK;
00018 private System.Windows.Forms.Button btnCancel;
00022 private System.ComponentModel.Container components = null;
00023
00024 public InputForm()
00025 {
00026 InitializeComponent();
00027 }
00028
00029 private static InputForm Instance
00030 {
00031 get{
00032 if(inForm==null) inForm = new InputForm();
00033 return inForm;
00034 }
00035 }
00036
00037 public static string GetUserInput(string title, string devaultValue)
00038 {
00039 return GetUserInput(title, devaultValue, false);
00040 }
00041
00042 public static string GetUserInput(string title, bool password)
00043 {
00044 return GetUserInput(title, "", password);
00045 }
00046
00047
00048 public static string GetUserInput(string title, string devaultValue, bool password)
00049 {
00050 Instance.Text = title;
00051 Instance.textBox1.Text = devaultValue;
00052 Instance.PasswordField = password;
00053 if(Instance.PromptForInput())
00054 {
00055 return Instance.textBox1.Text;
00056 }
00057 else
00058 {
00059 throw new Exception("Canceled by user");
00060 }
00061 }
00062
00063 public static string GetFileFromUser(string msg)
00064 {
00065 OpenFileDialog chooser = new OpenFileDialog();
00066 chooser.Title = msg;
00067 DialogResult returnVal = chooser.ShowDialog();
00068 if(returnVal == DialogResult.OK)
00069 {
00070 return chooser.FileName;
00071 }
00072 else
00073 {
00074 throw new Exception("Canceled by user");
00075 }
00076 }
00077
00078 public static bool PromptYesNo(String str)
00079 {
00080 DialogResult returnVal = MessageBox.Show(
00081 str,
00082 "SharpSSH",
00083 MessageBoxButtons.YesNo,
00084 MessageBoxIcon.Warning);
00085 return (returnVal==DialogResult.Yes);
00086 }
00087
00088 public static void ShowMessage(String message)
00089 {
00090 MessageBox.Show(
00091 message,
00092 "SharpSSH",
00093 MessageBoxButtons.OK,
00094 MessageBoxIcon.Asterisk);
00095 }
00096
00100 protected override void Dispose( bool disposing )
00101 {
00102 if( disposing )
00103 {
00104 if (components != null)
00105 {
00106 components.Dispose();
00107 }
00108 }
00109 base.Dispose( disposing );
00110 }
00111
00112 #region Windows Form Designer generated code
00117 private void InitializeComponent()
00118 {
00119 this.textBox1 = new System.Windows.Forms.TextBox();
00120 this.btnOK = new System.Windows.Forms.Button();
00121 this.btnCancel = new System.Windows.Forms.Button();
00122 this.SuspendLayout();
00123
00124
00125
00126 this.textBox1.Location = new System.Drawing.Point(56, 24);
00127 this.textBox1.Name = "textBox1";
00128 this.textBox1.Size = new System.Drawing.Size(160, 20);
00129 this.textBox1.TabIndex = 0;
00130 this.textBox1.Text = "";
00131
00132
00133
00134 this.btnOK.Location = new System.Drawing.Point(56, 64);
00135 this.btnOK.Name = "btnOK";
00136 this.btnOK.TabIndex = 1;
00137 this.btnOK.Text = "OK";
00138 this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
00139
00140
00141
00142 this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
00143 this.btnCancel.Location = new System.Drawing.Point(144, 64);
00144 this.btnCancel.Name = "btnCancel";
00145 this.btnCancel.TabIndex = 2;
00146 this.btnCancel.Text = "Cancel";
00147 this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
00148
00149
00150
00151 this.AcceptButton = this.btnOK;
00152 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
00153 this.CancelButton = this.btnCancel;
00154 this.ClientSize = new System.Drawing.Size(264, 110);
00155 this.Controls.Add(this.btnCancel);
00156 this.Controls.Add(this.btnOK);
00157 this.Controls.Add(this.textBox1);
00158 this.Name = "InputForm";
00159 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
00160 this.Text = "Form1";
00161 this.ResumeLayout(false);
00162
00163 }
00164 #endregion
00165
00166 bool okBtnClicked = false;
00167
00168 private void btnOK_Click(object sender, System.EventArgs e)
00169 {
00170 okBtnClicked = true;
00171 this.Hide();
00172 }
00173
00174 private void btnCancel_Click(object sender, System.EventArgs e)
00175 {
00176 okBtnClicked = false;
00177 this.textBox1.Text = "";
00178 this.Hide();
00179 }
00180
00181 public bool PromptForInput()
00182 {
00183 this.ShowDialog();
00184 return okBtnClicked;
00185 }
00186
00187 public string getText()
00188 {
00189 return textBox1.Text;
00190 }
00191
00192 public bool PasswordField
00193 {
00194 get
00195 {
00196 return (textBox1.PasswordChar.Equals(0));
00197 }
00198 set
00199 {
00200 if (value)
00201 textBox1.PasswordChar='*';
00202 else
00203 textBox1.PasswordChar=(char)0;
00204 }
00205 }
00206 }
00207 }