Software Development Network>> Visual C#>> input box
There is a input box in vb.NET is there one in c#. If so can you give me an example
If you don't mind VB.NET runtime dependency in C# application, you can even add a reference to Microsoft.VisualBasic assembly and call InputBox function implemented there:
string message = "Enter a value between 1 and 3";
string title = "InputBox Demo";
string defaultResponse = "1";
//Display dialog at position 100, 100
Microsoft.VisualBasic.Interaction.InputBox(
message, title, defaultResponse, 100, 100);
input box
SMB
If you don't mind VB.NET runtime dependency in C# application, you can even add a reference to Microsoft.VisualBasic assembly and call InputBox function implemented there:
string message = "Enter a value between 1 and 3";
string title = "InputBox Demo";
string defaultResponse = "1";
//Display dialog at position 100, 100
Microsoft.VisualBasic.Interaction.InputBox(
message, title, defaultResponse, 100, 100);
Codeurai
using System;
namespace MyNamespace
{
public class InputDialog : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtInput;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button cmdOK;
private System.Windows.Forms.Button cmdCancel;
public string Value
{
get
{
return txtInput.Text;
}
set
{
txtInput.Text = value;
}
}
public InputDialog()
{
// Required for Windows Form Designer support
InitializeComponent();
}
private void InitializeComponent()
{
this.txtInput = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.cmdOK = new System.Windows.Forms.Button();
this.cmdCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(48, 16);
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size(232, 20);
this.txtInput.TabIndex = 0;
this.txtInput.Text = "";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(33, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Input:";
//
// cmdOK
//
this.cmdOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.cmdOK.Location = new System.Drawing.Point(69, 48);
this.cmdOK.Name = "cmdOK";
this.cmdOK.TabIndex = 2;
this.cmdOK.Text = "OK";
//
// cmdCancel
//
this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cmdCancel.Location = new System.Drawing.Point(149, 48);
this.cmdCancel.Name = "cmdCancel";
this.cmdCancel.TabIndex = 2;
this.cmdCancel.Text = "Cancel";
//
// Form1
//
this.AcceptButton = this.cmdOK;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cmdCancel;
this.ClientSize = new System.Drawing.Size(292, 86);
this.Controls.Add(this.cmdOK);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtInput);
this.Controls.Add(this.cmdCancel);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}
Now you can use it like this:
InputDialog dialog = new InputDialog();
if( dialog.ShowDialog( this ) == DialogResult.OK )
{
MessageBox.Show( this, "User had inputted: '" + dialog.Value + "'.");
}