簡單的c#問題急. vb.net中的inputbox() function 在c#中用what 替代 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一样的,共用的.net类库及其控件等.只是语法不一样而已 ChengKing(Enthusiasm Bigrosoft) 你是添加什么引用的? c#里没有,不过可以自己写。1.写一个类InputBox代替inputbox()using System; using System.Windows.Forms; namespace Input { /// <summary> /// clsInputBox 的摘要说明。 /// </summary> public class InputBox : System.Windows.Forms.Form { private System.Windows.Forms.TextBox txtData; private System.Windows.Forms.Label lblInfo; 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.txtData = new System.Windows.Forms.TextBox(); this.lblInfo = new System.Windows.Forms.Label(); this.SuspendLayout(); // // txtData // this.txtData.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.txtData.Location = new System.Drawing.Point(19, 8); this.txtData.Name = "txtData"; this.txtData.Size = new System.Drawing.Size(317, 23); this.txtData.TabIndex = 0; this.txtData.Text = ""; this.txtData.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtData_KeyDown); // // lblInfo // this.lblInfo.BackColor = System.Drawing.SystemColors.Info; this.lblInfo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.lblInfo.FlatStyle = System.Windows.Forms.FlatStyle.System; this.lblInfo.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.lblInfo.ForeColor = System.Drawing.Color.Gray; this.lblInfo.Location = new System.Drawing.Point(19, 32); this.lblInfo.Name = "lblInfo"; this.lblInfo.Size = new System.Drawing.Size(317, 16); this.lblInfo.TabIndex = 1; this.lblInfo.Text = "[Enter]确认 | [Esc]取消"; // // InputBox // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(350, 48); this.ControlBox = false; this.Controls.Add(this.lblInfo); this.Controls.Add(this.txtData); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "InputBox"; this.Text = "InputBox"; this.ResumeLayout(false); } //对键盘进行响应 private void txtData_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if(e.KeyCode == Keys.Enter) { this.Close(); } else if (e.KeyCode == Keys.Escape ) { txtData.Text = string.Empty ; this.Close(); } } //显示InputBox public static string ShowInputBox(string Title,string keyInfo) { InputBox inputbox = new InputBox(); inputbox.Text =Title; if (keyInfo.Trim() != string.Empty ) inputbox.lblInfo.Text =keyInfo; inputbox.ShowDialog(); return inputbox.txtData.Text; } } } ///////////////////////////////////////////////////////////////////////////////2.调用 private void button1_Click(object sender, System.EventArgs e) { string inMsg= Input.InputBox.ShowInputBox("输入信息",string.Empty ); //对用户的输入信息进行检查 if (inMsg.Trim() != string.Empty ) { MessageBox.Show(inMsg); } else { MessageBox.Show("输入为string.Empty"); } } 服务端为动态ip, 和客户端通过socket链接通讯,发现经常断开不稳定. 怎样在父窗口中改变子窗口的值 多线程效率问题 我制作的.net程序怎么能在没有.framework的机器上运行啊? C#可以这样做吗?利用变量存储一个判断条件。例如: 顶者有分~~!!!导出数据到Excel总是出错。数据量超过三万条,一次性导出到Excel.使用C#语言写 菜鸟:请大家提提关于时间算法的意见 求一XPath写法 c#五指棋代码 新手提问,急急急!!!很简单的问题 收集C#,.NET面试试题 C#.net Winform打包和部署
只是语法不一样而已
你是添加什么引用的?
1.写一个类InputBox代替inputbox()
using System; using System.Windows.Forms; namespace Input { /// <summary> /// clsInputBox 的摘要说明。 /// </summary> public class InputBox : System.Windows.Forms.Form { private System.Windows.Forms.TextBox txtData; private System.Windows.Forms.Label lblInfo; 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.txtData = new System.Windows.Forms.TextBox(); this.lblInfo = new System.Windows.Forms.Label(); this.SuspendLayout(); // // txtData // this.txtData.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.txtData.Location = new System.Drawing.Point(19, 8); this.txtData.Name = "txtData"; this.txtData.Size = new System.Drawing.Size(317, 23); this.txtData.TabIndex = 0; this.txtData.Text = ""; this.txtData.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtData_KeyDown); // // lblInfo // this.lblInfo.BackColor = System.Drawing.SystemColors.Info; this.lblInfo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.lblInfo.FlatStyle = System.Windows.Forms.FlatStyle.System; this.lblInfo.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.lblInfo.ForeColor = System.Drawing.Color.Gray; this.lblInfo.Location = new System.Drawing.Point(19, 32); this.lblInfo.Name = "lblInfo"; this.lblInfo.Size = new System.Drawing.Size(317, 16); this.lblInfo.TabIndex = 1; this.lblInfo.Text = "[Enter]确认 | [Esc]取消"; // // InputBox // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(350, 48); this.ControlBox = false; this.Controls.Add(this.lblInfo); this.Controls.Add(this.txtData); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "InputBox"; this.Text = "InputBox"; this.ResumeLayout(false); } //对键盘进行响应 private void txtData_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if(e.KeyCode == Keys.Enter) { this.Close(); } else if (e.KeyCode == Keys.Escape ) { txtData.Text = string.Empty ; this.Close(); } } //显示InputBox public static string ShowInputBox(string Title,string keyInfo) { InputBox inputbox = new InputBox(); inputbox.Text =Title; if (keyInfo.Trim() != string.Empty ) inputbox.lblInfo.Text =keyInfo; inputbox.ShowDialog(); return inputbox.txtData.Text; } } }
///////////////////////////////////////////////////////////////////////////////
2.调用
private void button1_Click(object sender, System.EventArgs e)
{
string inMsg= Input.InputBox.ShowInputBox("输入信息",string.Empty ); //对用户的输入信息进行检查 if (inMsg.Trim() != string.Empty )
{
MessageBox.Show(inMsg);
}
else {
MessageBox.Show("输入为string.Empty");
} }