Reputation: 7550
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
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
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
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