Damiel
Damiel

Reputation: 71

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

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

Upvotes: 5

Views: 1257

Answers (2)

CTABUYO
CTABUYO

Reputation: 712

The problem is that you are calling this method:

this.Close();

So like that you are closing the application, so try like this:

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

I would suggest not to call methods like Det, because depending on which libraries you are using, Det might be something else's name, so that might break your program.

Upvotes: -1

Reza Aghaei
Reza Aghaei

Reputation: 125187

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.

Upvotes: 7

Related Questions