委托用的很好
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestDialog
{
class Program
{
static void Main(string[] args)
{
Application.Run(new MainForm());
}
}
class MainForm : Form
{
Button cmdTest;
public MainForm()
{
this.SetBounds(0, 0, 300, 400);
this.StartPosition = FormStartPosition.CenterScree
n;
this.Text = "Main Form";
cmdTest = new Button();
cmdTest.SetBounds(100, 180, 100, 40);
cmdTest.Text = "Test";
cmdTest.Click += (o, e) =>
{
TestForm frm = new TestForm();
frm.ShowDialog();
MessageBox.Show("DialogResult: " + frm.DialogRe
sult);
};
this.Controls.Add(cmdTest);
}
}
class TestForm : Form
{
Button cmdTest;
TextBox txtTest;
public TestForm()
{
this.SetBounds(0, 0, 200, 200);
this.StartPosition = FormStartPosition.CenterParen
t;
this.Text = "Test Form";
txtTest = new TextBox();
txtTest.SetBounds(50, 50, 100, 30);
cmdTest = new Button();
cmdTest.SetBounds(70, 100, 60, 40);
cmdTest.Text = "Test";
cmdTest.Click += (o, e) =>
{
if (txtTest.Text == "123") this.DialogResult =
System.Windows.Forms.DialogResult.OK;
};
this.Controls.Add(cmdTest);
this.Controls.Add(txtTest);
}
}
}
利用 VB
原创:.NET C# 弹出 VB 输入对话框
1、WinForm 下,有时需要弹出一个能够接收用户输入的提示框,在 C# WinForm
下是不提供的,但是在 VB 类库中包括此功能,我们可以添加引用后,直接调用
就可以了(如下图 A)
2、string getValue=Microsoft.VisualBasic.Interaction.InputBox("请输入
参数 1:", "提示", "参数 1:", 400, 320);
3、运行结果截图:如下