Click here to Skip to main content
16,012,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
My problem is that when i am opening a form via clicking on form1, then form2 is not opens properly means all of its controls, buttons etc. are not appearing on it. so please suggest me what can i do for this.

Thank You.

Edit:

Form1:
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
         
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
        public void button1_Click(object sender, EventArgs e)
        {
            
            if (checkBox1.Checked || checkBox2.Checked)
            {
                label2.Visible = true;
                label3.Visible = true;
                label3.Text = "Will Be Your Life Partener";
                if (checkBox1.Checked)
                {
                    label2.Text = " Mrs." + textBox1.Text + " " + textBox2.Text;
                }
                else
                    label2.Text = "Mr." + textBox2.Text;
            }
            else
            {
                label2.Visible = true;
                label2.Text = "Please Select Your Prefix";
            }
         }

        public void button2_Click(object sender, EventArgs e)
        {
            label2.Visible = true;
            label3.Visible = false;
            label2.Text = "Thank You " + textBox1.Text;

            LF form2 = new LF(this);
            form2.ShowDialog();
        }

            private void label3_Click(object sender, EventArgs e)
            {

            }


            public string PublicProperty { get; set; }
    }


       
    }

Form2:
 public partial class LF : Form
    {
        public LF(Form1 parent)
        { this.parentForm = parent; }

        public LF()
        {
            InitializeComponent();
        }
   public void Form2_Load(object sender, EventArgs e)
        {
           
        }

       
        public void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Equals("vijay"))
            {
                label1.Text = "Mrs. Pareek";
            }
        }

        public void button2_Click(object sender, EventArgs e)
        {
            label1.Text = "Thank You" + textBox1.Text;
        }

       

        public Form1 parentForm { get; set; }
}
Posted
Updated 24-Mar-13 12:37pm
v2
Comments
Kenneth Haugland 24-Mar-13 17:53pm    
We need code for this
Vijay Pareek 24-Mar-13 18:08pm    
i Have posted code see this.

1 solution

You problem is in
public LF(Form1 parent) { this.parentForm = parent; }


You need to call InitializeComponent;

public LF(Form1 parent)
 {
    this.parentForm = parent; 
    InitializeComponent();
 }
 
Share this answer
 
v2
Comments
Vijay Pareek 24-Mar-13 18:22pm    
Thank You its Working...
[no name] 24-Mar-13 18:27pm    
You're welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900