0

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.

Posto
  • 7,362
  • 7
  • 44
  • 61
  • simply i want sample code for ".net c sharp windows form dialog box with a textbox and button" – Posto Nov 05 '09 at 07:00
  • Why have you asked the same question twice: http://stackoverflow.com/questions/1675101/net-c-windows-form-application-open-popup-window – Murph Nov 05 '09 at 08:17

3 Answers3

2

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
Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
  • 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 Nov 05 '09 at 08:19
1

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
  • 344,408
  • 85
  • 689
  • 683
0

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
  • 3,057
  • 18
  • 32
  • 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 Nov 05 '09 at 08:20
  • 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 Nov 05 '09 at 14:05