nauman_gcu 0 Newbie Poster

I have Windows Form which is implemented as per singleton pattern and having TableLayoutPanel as container on it for other controls to be placed on it and it is generating an anonymous problem regarding controls movement in which they changes their position when set as mdiChildForm of a mdiParent Form. In this scenario if a windows Form is not being implemented by singleton pattern then it is working fine and if not then the Controls like lable and others are changing their location when the form appear on screen inside mdiparent second time by the user. The further detail regarding this problem is described below.

There are two Forms named as UI-1 and UI-2 and one Is the MDIParent Form named as MainForm.

Form UI-1 has the singleton pattern implementation and can only be initialized by GetInstance() method as you can see from code given below.


The code In the UI-1 Form:

public partial class UI1 : Form
    {
        private static UI1 frm;
     
        public static UI1 GetInstance()
        {
            if (frm == null)
            {
                frm = new UI1();
            }
            return frm;
        }

        private UI1()
        {
            InitializeComponent();
        }

        public void ShowLabelCoordinates()
        {
            MessageBox.Show("Location: " + this.label1.Location.ToString() + " Position: "+ 
              this.label1.PointToScreen(this.label1.Location).ToString());
        }
    }


Form UI-2 is with its usual constructor and can be initialized directly from it as you can see from code given below.

public partial class UI2 : Form
    {
        public UI2()
        {
            InitializeComponent();
        }
    }

The code in the main Form which is actually a mdi Parent Form.

UI1 frm = UI1.GetInstance();
            frm.MdiParent = this;
            frm.Show();
            frm.Focus();
            frm.ShowLabelCoordinates();

UI2 frm = new UI2();
            frm.MdiParent = this;
            frm.Show();
            frm.Focus();

Any immediate assistance will be highly appreciated.
<<snip>>