0

I have followed the steps here http://msdn.microsoft.com/en-us/library/ms185301.aspx to create a wizard that allows me to use a custom string when creating a new project from my Visual Studio Template.

But this example adds a textbox to the wizards Form like so:

public partial class UserInputForm : Form
{
    private string customMessage;
    private TextBox textBox1;

    public UserInputForm()
    { 
        textBox1 = new TextBox();
        this.Controls.Add(textBox1);
    }

    public string get_CustomMessage()
    {
        return customMessage;
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        customMessage = textBox1.Text;
        this.Dispose();
    }
}

I want my Dialog to be a little bit more detailed so I have used the Dialog editor to drop a Textbox on like so:

enter image description here

This causes the following auto generated code to appear: enter image description here

Now when I do this I notice that the newly dropped textbox does not appear when I create my project. Only the one that has been specified in the Constructor like so: enter image description here

Why is this so? I want to add lots of text boxes and labels on the wizard so I don't want to be having to do this all in code in the constructor.

Harry Boy
  • 4,159
  • 17
  • 71
  • 122
  • 1
    They kept the example simple. But a real Form class doesn't look like that, it calls InitializeComponent() in its constructor. Since you didn't do that, you can't get the textbox either. – Hans Passant May 29 '14 at 14:51

1 Answers1

1

Somewhere along the line, the call to InitializeComponent got dropped from your constructor. Just add a call to it and you'll be fine.

By the same token, if you're using the designer, it's bad form to create controls yourself in the constructor. Just add them in the designer.

João Mendes
  • 1,719
  • 15
  • 32