,C#中没有类似System.Windows.Forms.MessageBox.Show()的InputBox.Show()函数和类。 作为一个workaround,可以使用Visual Basic.NET runtime中的InputBox函数。下面是例子代码: string result= " ";
Microsoft.VisualBasic.Interaction.InputBox( "type your name ", "input ",result,0,0); 也可以自己写:
写一段很简单的代码来实现类似的功能。下面是microsoft.public.dotnet.languages.csharp讨论组中的一个例子,可以通过调用InputBox.ShowInputBox方法来显示这个InputBox并获取结果: public class InputBox : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.Container components = null; private InputBox()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 16);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
this.textBox1.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
//
// InputBox
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 53);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "InputBox";
this.Text = "InputBox";
this.ResumeLayout(false); } private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
this.Close();
} public static string ShowInputBox()
{
InputBox box = new InputBox();
box.ShowDialog();
return box.textBox1.Text;
}
}
Microsoft.VisualBasic.Interaction.InputBox( "type your name ", "input ",result,0,0); 也可以自己写:
写一段很简单的代码来实现类似的功能。下面是microsoft.public.dotnet.languages.csharp讨论组中的一个例子,可以通过调用InputBox.ShowInputBox方法来显示这个InputBox并获取结果: public class InputBox : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.Container components = null; private InputBox()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 16);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
this.textBox1.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
//
// InputBox
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 53);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "InputBox";
this.Text = "InputBox";
this.ResumeLayout(false); } private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
this.Close();
} public static string ShowInputBox()
{
InputBox box = new InputBox();
box.ShowDialog();
return box.textBox1.Text;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货