Failed Scientist
Failed Scientist

Reputation: 2027

Windows form not showing control C#

I have made a windows form application (which has been running fine for more than couple of weeks). Now I wanted to add another form in it (which should be displayed to show extra properties of item whose value is being shown in rich textbox)

Here is my code for double click (to show details window):

private void richTextBox1_DoubleClick(object sender, EventArgs e)
{
    //Using parameterized constructor since I need an input from parent form
    Form2 formETView = new Form2(richTextBox1.Text.Substring(1, 15));
    formETView.Show();
}

As a reference, constructor of Form2 is:

public Form2(string p)
{
    // TODO: Complete member initialization
    trans_ID = p;            
}

But it shows only this screen:

enter image description here

While actual screen has couple of controls:

enter image description here

Any help in this regard will be really appreciated.

P.S: Is the approach to use parameterized constructor to pass data as argument in child window incorrect? Please let me know if it's the case.

Upvotes: 0

Views: 4451

Answers (2)

Esteban Verbel
Esteban Verbel

Reputation: 738

Just call InitializeComponent() in your constructor function. That initializes all the controls of the form.

Upvotes: 1

Alessandro D'Andria
Alessandro D'Andria

Reputation: 8878

Use

public Form2(string p) : this()

This way you call default constructor that calls InitializeComponents.

Upvotes: 2

Related Questions