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.
+2
A:
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
ArsenMkrt
2009-11-05 06:40:03
can you give me the real code , I am very new to this
openidsujoy
2009-11-05 06:46:13
Erm, that is real code - sort of writing your application for you there's not a huge amount more we can do. This is fairly fundamental stuff.
Murph
2009-11-05 08:19:04
+1
A:
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.
Joey
2009-11-05 06:40:52
A:
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);
j.a.estevan
2009-11-05 07:50:03
You should set the properties of the button to be OK that way you don't need to manually set the dialog result and to ensure the correct behaviour of the buttons in the form.
Murph
2009-11-05 08:20:33
that's true but like he asked for the "exact" form, this is the only way I can "paste" it xD. Not very smart, but it works.
j.a.estevan
2009-11-05 14:05:42