user1479485
user1479485

Reputation: 79

showing usercontrol controls in c# window form

I want to show all usercontrols in window forms I add usercontol in window form and try to show them using show() method. but nothing is Shown up on the window. Can any one please tell how to do this.

I am having following troubled code (in C#)

private void patientform_Load(object sender, EventArgs e)
{
    patient p = new patient();
    patientform patienfrm = new patientform();

    patienfrm.Controls.Add(p);
    patienfrm.Show();
    Control[] ctrl = this.Controls.Find("textBox1", true);
    //String c = ctrl[0].Text;
    //label1.Text = c;

Upvotes: 0

Views: 504

Answers (1)

danish
danish

Reputation: 5600

You care creating a new instance of same form which is already loaded. You need to refer to correct instance of the form.

I suppose you are trying to add Patient control to PatientForm. Following code would do that:

Controls.Add(new Patient());

You will have to set position and other properties to show it in right place with right anchoring and docking etc.

Upvotes: 1

Related Questions