Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Tired of Hibernate? Try JDBI in your code JDBI Quick sample ICategoryDAO.java : create a data access interface (implement is not required) package com.prhythm.erotic.task.data.... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement...
Blog Archive
Stats
InputBox in C#
/// <summary>
/// Summary description for InputBox.
///
public class InputBoxDialog : System.Windows.Forms.Form
{

    #region Windows Contols and Constructor

    private System.Windows.Forms.Label lblPrompt;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.TextBox txtInput;
    /// <summary>
    /// Required designer variable.
    ///
    private System.ComponentModel.Container components = null;

    public InputBoxDialog()
    {
        //
        // Required for Windows Form Designer support
        //
        InitializeComponent();

        //
        // TODO: Add any constructor code after InitializeComponent call
        //
    }

    #endregion

    #region Dispose

    /// <summary>
    /// Clean up any resources being used.
    ///
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            if (components != null)
            {
                components.Dispose();
            }
        }
        base.Dispose(disposing);
    }

    #endregion

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///
    private void InitializeComponent()
    {
        this.lblPrompt = new System.Windows.Forms.Label();
        this.button1 = new System.Windows.Forms.Button();
        this.txtInput = new System.Windows.Forms.TextBox();
        this.btnOK = new System.Windows.Forms.Button();
        this.SuspendLayout();
        //
        // lblPrompt
        //
        this.lblPrompt.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.lblPrompt.BackColor = System.Drawing.SystemColors.Control;
        this.lblPrompt.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.lblPrompt.Location = new System.Drawing.Point(12, 17);
        this.lblPrompt.Name = "lblPrompt";
        this.lblPrompt.Size = new System.Drawing.Size(303, 22);
        this.lblPrompt.TabIndex = 3;
        //
        // button1
        //
        this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        this.button1.Location = new System.Drawing.Point(323, 45);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(64, 27);
        this.button1.TabIndex = 2;
        this.button1.Text = "&Cancel";
        this.button1.Click += new System.EventHandler(this.button1_Click);
        //
        // txtInput
        //
        this.txtInput.Location = new System.Drawing.Point(8, 78);
        this.txtInput.Name = "txtInput";
        this.txtInput.Size = new System.Drawing.Size(379, 22);
        this.txtInput.TabIndex = 0;
        this.txtInput.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtInput_KeyPress);
        //
        // btnOK
        //
        this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
        this.btnOK.Location = new System.Drawing.Point(323, 12);
        this.btnOK.Name = "btnOK";
        this.btnOK.Size = new System.Drawing.Size(64, 27);
        this.btnOK.TabIndex = 1;
        this.btnOK.Text = "&OK";
        this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
        //
        // InputBoxDialog
        //
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
        this.ClientSize = new System.Drawing.Size(399, 111);
        this.Controls.Add(this.txtInput);
        this.Controls.Add(this.button1);
        this.Controls.Add(this.btnOK);
        this.Controls.Add(this.lblPrompt);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.Name = "InputBoxDialog";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "InputBox";
        this.Load += new System.EventHandler(this.InputBox_Load);
        this.ResumeLayout(false);
        this.PerformLayout();

    }
    #endregion

    #region Private Variables
    string formCaption = string.Empty;
    string formPrompt = string.Empty;
    string inputResponse = string.Empty;
    string defaultValue = string.Empty;
    DialogResult clickedButton;
    #endregion

    #region Public Properties
    public string FormCaption
    {
        get { return formCaption; }
        set { formCaption = value; }
    } // property FormCaption
    public string FormPrompt
    {
        get { return formPrompt; }
        set { formPrompt = value; }
    } // property FormPrompt
    public string InputResponse
    {
        get { return inputResponse; }
        set { inputResponse = value; }
    } // property InputResponse
    public string DefaultValue
    {
        get { return defaultValue; }
        set { defaultValue = value; }
    } // property DefaultValue
    public DialogResult ClickedButton
    {
        get { return clickedButton; }
    }
    #endregion

    #region Form and Control Events
    private void InputBox_Load(object sender, System.EventArgs e)
    {
        this.txtInput.Text = defaultValue;
        this.lblPrompt.Text = formPrompt;
        this.Text = formCaption;
        this.txtInput.SelectionStart = 0;
        this.txtInput.SelectionLength = this.txtInput.Text.Length;
        this.txtInput.Focus();
    }


    private void btnOK_Click(object sender, System.EventArgs e)
    {
        this.clickedButton = DialogResult.OK;
        InputResponse = this.txtInput.Text;
        this.Close();
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
        this.clickedButton = DialogResult.Cancel;
        this.Close();
    }

    public static string InputBox(string prompt, string title, string defaultValue)
    {
        InputBoxDialog ib = new InputBoxDialog();
        ib.FormPrompt = prompt;
        ib.FormCaption = title;
        ib.DefaultValue = defaultValue;
        ib.ShowDialog();
        string s = ib.InputResponse;
        ib.Close();
        return s;
    }// method: InputBox

    private Button btnOK;

    private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 13)
        {
            btnOK_Click(sender, e);
            e.Handled = true;
        }
    }
    #endregion
}