Posto
Posto

Reputation: 7550

.net c sharp windows Form Application dialog box

I want to open a small box , when my application starts, where user can enter their name , and I want that name to use in my application. I am using Windows Form Application and C#. I am vary new to this, any idea how to implement this.

Upvotes: 0

Views: 1995

Answers (3)

j.a.estevan
j.a.estevan

Reputation: 3097

This is the form:

public partial class fmUserName : Form
{
    public string UserName
    {
        get { return txName.Text; }
    }

    public fmUserName()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.DialogResult = DialogResult.OK;
        this.Close();
    }
}

Then you can call it :

fmUserName fm = new fmUserName();
fm.ShowDialog();

MessageBox.Show("Hello " + fm.UserName);

Upvotes: 0

Joey
Joey

Reputation: 354456

Create a form, stick a textbox and an "OK" button on it, create a public property which contains the textbox's contents you can access afterwards.

Upvotes: 1

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50712

Create a form UserNameForm with textbox and open button on it and a property that returns and sets textBoxes text property, than open it when you want like this

UserNameForm unf = new UserNameForm();
unf.ShowDialog();
unf.UserName // give property value

Upvotes: 2

Related Questions