Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form doesn't show controls, It shows an empty form

Tags:

c#

.net

winforms

Details form doesn't show anything even when it is called from the Welcome form.

here's all the code (its like login-signup project):

Details Form

namespace D
{
    public partial class Details : Form
    {
        public string dtext1;
        public string orform = string.Empty;
        public string orform2 = string.Empty;
        public string orform3 = string.Empty;
        public string orform4 = string.Empty;
        public Details(string incomform,string incomform2,string incomform3,string incomform4)
        {
            InitializeComponent();
            orform = incomform;
            orform2 = incomform2;
            orform3 = incomform3;
            orform4 = incomform4;
        }

        public Details() 
        {
        }

        private void Details_Load(object sender, EventArgs e)
        {
            textBox1.Text = orform;
            textBox2.Text = orform2;
            textBox3.Text = orform3;
            textBox4.Text = orform4;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}

Welcome Form

namespace D
{
    public partial class Welcome : Form
    {

        public Welcome()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           Details Det = new Details();
            Det.ShowDialog();
            this.Close();
        }
    }
}

any help/advice would be really a big legit help

like image 384
Damiel Avatar asked Nov 29 '15 20:11

Damiel


1 Answers

The problem is with your Details form constructor that you didn't call InitializeComponent(); in it. Change it to this:

public Details() 
{
    InitializeComponent();
}

All designer generated codes including your controls definition and properties and layout is in InitializeComponent and it should be called in your form the constructor to add controls to your form and perform layout.

like image 139
Reza Aghaei Avatar answered Sep 18 '22 12:09

Reza Aghaei