0

I used this code for the secondary form to act / be like mdi, this is windows form C#

        frmFontLoad fontLoad = new frmFontLoad();
        
        fontLoad.TopLevel = false;
        Controls.Add(fontLoad);
        fontLoad.Show();
        fontLoad.BringToFront();

but the result then the form was loaded is like this refer to screenshot:

Form

Code on Form Load:

  private void frmLabelPNInput_Load(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.CenterScreen;

            Printer_SerialPort = new SerialPort(ConfigurationManager.AppSettings["Printer_com_port"]);

            btnOk.Enabled = false;
        }

how can i make this secondary form to be displayed at the center?

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • Setting the StartPosition property in the Load event is too late. But setting TopLevel to false is the core problem, the form no longer behaves like a form anymore. It is strongly similar to a UserControl, the StartPosition property no longer has any affect. Nor does it in any way resemble an MDI child. Like a UserControl, you have to set its Location property to get it where you want it. – Hans Passant Mar 14 '22 at 07:47
  • are you want to display your window center screen of windows display or parent screen ? – Ahmad Mar 14 '22 at 07:58
  • this link has multiple solutions for showing center screen https://stackoverflow.com/questions/4601827/how-do-i-center-a-window-onscreen-in-c – Ahmad Mar 14 '22 at 08:09

1 Answers1

0
        frmProgress progress = new frmProgress();
        progress.Left = (this.ClientSize.Width - progress.Width) / 2;
        progress.Top = (this.ClientSize.Height - progress.Height) / 2;

This solved my problem, thanks