.NET C#Windows窗体应用程序:打开弹​​出窗口

.NET C#Windows窗体应用程序:打开弹​​出窗口

问题描述:

我使用Windows窗体应用程序。我想开一个小的文本框在一个窗口中启动该程序中输入用户名或电子邮件。

I am using Windows Form application. I want to open a small textbox on a window to enter user's name or Email in Starting for the program.

我怎样才能做到这一点?

How can I achieve this?

写了一个,这是一件几乎微不足道(创建表单并添加标签,文本框和按钮),并使用VB一个perputating的东西,只投入到安抚并柜暴徒。

Write one, 'tis almost trivial (creating the form and adding label, textbox and buttons) and using the VB one is perputating something that was only put in to appease the baying mob.

主要方法是ShowDialog的(),这是一个表格上的方法。

Key method is ShowDialog() which is a method on a Form.

在表格请确保您设置的确定标志和正确的取消按钮,并提供一个属性(最好),让您阅读(如果有必要写)文本框中

On the form make sure you set the flags for the Ok and Cancel buttons correctly and provide a property (ideally) to allow you to read (and write if necessary) the text box

然后就可以做到大致如下的东西线:

You can then do something along the lines of the following:

using(MyInputForm mif = new MyInputForm)
{
    if (mif.ShowDialog() == DialogResult.OK)
    {
         dataFromDialog = mif.InputData;
    }
    else
    {
         // logic to deal with cancel
    }
}

您可以做在WPF类似的东西,没有一个例子,虽然手。

You can do something similar in WPF, don't have an example to hand though.