Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Windows Form with TableLayoutPanel is changing its Controls position when is shown in mdiParent Form. How to Resolve this Issue?

Windows Form with TableLayoutPanel is changing its Controls position when is shown in mdiParent Form. How to Resolve this Issue?

Scheduled Pinned Locked Moved Windows Forms
helpcomdesigndockerregex
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nouman_gcu
    wrote on last edited by
    #1

    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 change 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();

    Sample Application has been attached at this link http://www.eggheadcafe.com/fileupload/1355103023_mdiTestApp.zip Any immediate assistance will be highly appreciated. Muhammad Noman

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups