In VB, we have InputBox to allow a user to input text. Do we have a similar
one in VC#.net? Obviously, MessageBox can not do it.

Thanks.

RE: InputBox in VC#.net? by NigelArmstrong

NigelArmstrong
Wed Dec 01 10:29:12 CST 2004

Hi Andrew

I wrote a simple class to do this. let me know if you want me to post it...

Usage was similar to MessageBox - it was InputBox.Show(), returning a
String...so we had a static Show method on a class called Input Box, a
private constructor to create an instance, and handle the ShowDialog in the
static show method.

Nigel Armstrong

"Andrew" wrote:

> In VB, we have InputBox to allow a user to input text. Do we have a similar
> one in VC#.net? Obviously, MessageBox can not do it.
>
> Thanks.

Re: InputBox in VC#.net? by Herfried

Herfried
Wed Dec 01 10:38:26 CST 2004

"Andrew" <Andrew@discussions.microsoft.com> schrieb:
> In VB, we have InputBox to allow a user to input text. Do we have a
> similar
> one in VC#.net? Obviously, MessageBox can not do it.

If you are lazy, add a reference to "Microsoft.VisualBasic.dll" and use
'Microsoft.VisualBasic.Interaction.InputBox'...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Re: InputBox in VC#.net? by Tim

Tim
Wed Dec 01 10:42:47 CST 2004

If you want, you can actually still use the VB InputBox. Just include a
reference to the "Microsoft.VisualBasic.dll" assembly.

string s = Microsoft.VisualBasic.Interaction.InputBox("Message", "Title",
"Default", 0, 0);

--
Tim Wilson
.Net Compact Framework MVP

"Andrew" <Andrew@discussions.microsoft.com> wrote in message
news:FFB089E2-EFC5-4E4C-B3C8-2483AE29503D@microsoft.com...
> In VB, we have InputBox to allow a user to input text. Do we have a
similar
> one in VC#.net? Obviously, MessageBox can not do it.
>
> Thanks.



RE: InputBox in VC#.net? by Andrew

Andrew
Wed Dec 01 10:59:11 CST 2004

Yes, please...

"Nigel Armstrong" wrote:

> Hi Andrew
>
> I wrote a simple class to do this. let me know if you want me to post it...
>
> Usage was similar to MessageBox - it was InputBox.Show(), returning a
> String...so we had a static Show method on a class called Input Box, a
> private constructor to create an instance, and handle the ShowDialog in the
> static show method.
>
> Nigel Armstrong
>
> "Andrew" wrote:
>
> > In VB, we have InputBox to allow a user to input text. Do we have a similar
> > one in VC#.net? Obviously, MessageBox can not do it.
> >
> > Thanks.

RE: InputBox in VC#.net? by NigelArmstrong

NigelArmstrong
Wed Dec 01 14:23:02 CST 2004

Hi Andrew

Apologies for the length of this post...

Built using the design time environment...

HTH

Nigel Armstrong

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace CSharpInputBox
{
/// <summary>
/// Summary description for InputBox.
/// </summary>
public class InputBox : System.Windows.Forms.Form
{
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Label promptLabel;
private System.Windows.Forms.TextBox inputTextBox;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

private InputBox()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

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

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

private static InputBox inputBox = null;
public static string Show(string Prompt, string Title, string
DefaultResponse)
{
if (inputBox == null)
{
inputBox = new InputBox();
}
inputBox.promptLabel.Text = Prompt;
inputBox.Text = Title;
inputBox.inputTextBox.Text = DefaultResponse;
if (inputBox.ShowDialog() == DialogResult.OK)
{
return inputBox.inputTextBox.Text;
}
else
{
return String.Empty;
}
}

public static string Show(string Prompt)
{
return Show(Prompt, Application.ProductName, String.Empty);
}

public static string Show(string Prompt, string Title)
{
return Show(Prompt, Title, String.Empty);
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.promptLabel = new System.Windows.Forms.Label();
this.inputTextBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// buttonOK
//
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.Location = new System.Drawing.Point(304, 16);
this.buttonOK.Name = "buttonOK";
this.buttonOK.TabIndex = 0;
this.buttonOK.Text = "OK";
//
// buttonCancel
//
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(304, 48);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.TabIndex = 1;
this.buttonCancel.Text = "Cancel";
//
// promptLabel
//
this.promptLabel.Location = new System.Drawing.Point(8, 16);
this.promptLabel.Name = "promptLabel";
this.promptLabel.Size = new System.Drawing.Size(288, 104);
this.promptLabel.TabIndex = 2;
this.promptLabel.Text = "label1";
//
// inputTextBox
//
this.inputTextBox.Location = new System.Drawing.Point(8, 128);
this.inputTextBox.Name = "inputTextBox";
this.inputTextBox.Size = new System.Drawing.Size(368, 20);
this.inputTextBox.TabIndex = 3;
this.inputTextBox.Text = "";
//
// InputBox
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(384, 164);
this.Controls.Add(this.inputTextBox);
this.Controls.Add(this.promptLabel);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InputBox";
this.Text = "InputBox";
this.ResumeLayout(false);

}
#endregion
}
}