locked
Duplicated winform RRS feed

  • Question

  • Hi, 

    I have some troubles to figure out why a winform is showed twice.

    I have the Main form and a panel inside of it which shows (focus) / hide some forms depending on tree clicks in the left section.

    there are childs forms that are instanciated only once in the main constructor.

    Two of them seem to be fine. The last one is duplicated one on the bottom of the other.

    I did a test by putting a message box inside each child constructor and it's been fired only once for each child.

    By the way, that duplicated form on the bottom of the first one is not populated with datas.

    Can anyone give me an idea? or if I am not clear, let me know which details you wanna know.

    Thank you.


    • Edited by Intiko81 Monday, August 25, 2014 7:08 PM
    Monday, August 25, 2014 6:56 PM

Answers

  • Hmm very strange.

    Yesterday I tried to look at the form properties and tried to set the IsMdiContainer to true.

    At runtime, it crashed at the line this.TopLevel = false; in the constructor form. So I put back to false (IsMdiContainer = false). Ran the app again and the duplicated form went away! wow!

    If you ever had an idea what was the problem, you could tell me. I will be too curious.

    Thank you.

    • Proposed as answer by Cor Ligthert Thursday, August 28, 2014 9:51 AM
    • Marked as answer by Carl Cai Tuesday, September 2, 2014 9:05 AM
    Wednesday, August 27, 2014 1:43 PM

All replies

  • hi,

    can you please post your code sample?

    Thank You,

    Sammani

    Tuesday, August 26, 2014 4:45 AM
  • Hi,

    Please tell me which part of the code you wanna take a look at ?

    I will try to post most revelant parts, let me know if you want to know more details.

    Thank you.

    In the main form I have this method that is called from the main constructor.

           

    private void initialiserForms()
            {
                formAjoutCategorie = new AjoutCategorieForm();
                formAjoutPrototype = new AjoutPrototypeForm();            
                formAjoutRapport = new AjoutRapportForm();

    // delegates
                formAjoutCategorie.majArbreBibliotheque = new AjoutCategorieForm.MajArbreBibliotheque(majArbreBibliotheque);
                formAjoutPrototype.majArbreBibliotheque = new AjoutPrototypeForm.MajArbreBibliotheque(majArbreBibliotheque);
                formAjoutRapport.majArbreBibliotheque = new AjoutRapportForm.MajArbreBibliotheque(majArbreBibliotheque);            

                formAjoutCategorie.MdiParent = this;
                formAjoutPrototype.MdiParent = this;
                formAjoutRapport.MdiParent = this;     
            }

    In the main form again we have this method. This method is called when I click on the tree to add something (report informations)

            private void ouvrirFormRapport(string idElement, string nomFichier, string idParent)
            {            
                try
                {
                    formAjoutRapport.peuplerForm(idElement, nomFichier, idParent);
                    pnlDroite.Controls.Clear();
                    formAjoutRapport.Parent = pnlDroite;
                    formAjoutRapport.Focus();
                }
                catch (RobicException ex)
                {
                    throw new RobicException("erreur lors du peuplement du formulaire d'ajout de rapport", NumeroException.ECHEC_OPERATION, ex);
                }
                catch (ExceptionBibliotheque)
                {
                    throw;
                }
            }

    The "peuplerForm" method that you see in the ouvrirFormRapport method is the child form method that populate that child form with datas. It retrieves datas form DB and makes some binding.

    Ah.. and finally the childs form constructor, I will show you one constructor. The other childs constructor are the same (same steps).

            public AjoutRapportForm()
                : base()
            {
                InitializeComponent();
                this.TopLevel = false;
                this.Visible = true;
                this.Anchor = AnchorStyles.Top;

                try
                {
                    initialiserParametresConfiguration();
                    initialiserFacades();
                    lierDonneesPreliminaires();
                }
                catch (RobicException ex)
                {
                    throw new RobicException("erreur lors du chargement du rapport ou l'initialisation des paramètres", NumeroException.ECHEC_OPERATION, ex);
                }
            }






    • Edited by Intiko81 Tuesday, August 26, 2014 8:29 PM
    Tuesday, August 26, 2014 3:49 PM
  • Hmm very strange.

    Yesterday I tried to look at the form properties and tried to set the IsMdiContainer to true.

    At runtime, it crashed at the line this.TopLevel = false; in the constructor form. So I put back to false (IsMdiContainer = false). Ran the app again and the duplicated form went away! wow!

    If you ever had an idea what was the problem, you could tell me. I will be too curious.

    Thank you.

    • Proposed as answer by Cor Ligthert Thursday, August 28, 2014 9:51 AM
    • Marked as answer by Carl Cai Tuesday, September 2, 2014 9:05 AM
    Wednesday, August 27, 2014 1:43 PM
  • Hmm very strange.

    Yesterday I tried to look at the form properties and tried to set the IsMdiContainer to true.

    At runtime, it crashed at the line this.TopLevel = false; in the constructor form. So I put back to false (IsMdiContainer = false). Ran the app again and the duplicated form went away! wow!

    If you ever had an idea what was the problem, you could tell me. I will be too curious.

    Thank you.

    How could we, you probably did something wrong, but we don't have your memory, not your eyes and not your hands.

    Success
    Cor

    Thursday, August 28, 2014 9:51 AM