Example #1
0
        /// <summary>
        /// On vérifie si la souris se situe vis-à-vis une vignette et s'il
        /// s'agit d'un clic droit ou gauche. Si c'est un clic gauche sur une vignette,
        /// on change l'information affichée sous l'image.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImagePro_MouseClick(object sender, MouseEventArgs e)
        {
            if (!m_imageEstMaximisé && e.Button != MouseButtons.Right)
            {
                // On crée un rectangle qui va contenir la portion de chaque vignette à tour de rôle
                // afin de vérifier si la position de la souris s'y situe.
                Rectangle recVignette = new Rectangle();
                recVignette.Size =
                    new Size(m_dossierCourant.TailleÉlément, m_dossierCourant.TailleÉlément);
                // On crée un "rectangle" qui va contenir la portion occupée par la souris
                Rectangle recSouris = new Rectangle(new Point(e.X, e.Y), new Size(1, 1));
                // On arrête de chercher si on a trouvé quelle image a été cliquée.
                bool aÉtéCliquée = false;
                int  indiceImage = -1;
                for (int i = m_dossierCourant.NbÉlémentsPage * m_dossierCourant.IndicePage;
                     !aÉtéCliquée && i != m_dossierCourant.Images.Count; ++i)
                {
                    recVignette.Location = m_dossierCourant.Images[i].Position;
                    aÉtéCliquée          = recVignette.IntersectsWith(recSouris);

                    if (aÉtéCliquée)
                    {
                        indiceImage = i;
                    }
                }

                using (Graphics g = CreateGraphics())
                {
                    if (aÉtéCliquée)
                    {
                        SizeF taille = g.MeasureString(m_dossierCourant.Images[indiceImage].InfosAffichées,
                                                       m_policeBase);
                        if (m_dossierCourant.Images[indiceImage].NomAffiché)
                        {
                            m_dossierCourant.Images[indiceImage].NomAffiché     = false;
                            m_dossierCourant.Images[indiceImage].InfosAffichées =
                                m_dossierCourant.Images[indiceImage].TaillesImage;
                        }
                        else
                        {
                            m_dossierCourant.Images[indiceImage].NomAffiché     = true;
                            m_dossierCourant.Images[indiceImage].InfosAffichées =
                                m_dossierCourant.Images[indiceImage].NomFichier;
                        }

                        g.FillRectangle(new SolidBrush(BackColor),
                                        m_dossierCourant.Images[indiceImage].Position.X,
                                        m_dossierCourant.Images[indiceImage].Position.Y
                                        + m_dossierCourant.TailleÉlément + BORDURE_INFOS,
                                        m_dossierCourant.TailleÉlément,
                                        (int)taille.Height);

                        // On coupe le texte si ce dernier dépasse la taille d'un élément.
                        string texteÉlément = m_dossierCourant.Images[indiceImage].InfosAffichées;
                        while (g.MeasureString(texteÉlément, m_policeBase).Width
                               > m_dossierCourant.TailleÉlément)
                        {
                            texteÉlément = texteÉlément.Substring(0, texteÉlément.Length - 1);
                        }

                        g.DrawString(texteÉlément, m_policeBase, Brushes.Black,
                                     m_dossierCourant.Images[indiceImage].Position.X
                                     + m_dossierCourant.TailleÉlément / 2
                                     - g.MeasureString(texteÉlément, m_policeBase).Width / 2,
                                     m_dossierCourant.Images[indiceImage].Position.Y
                                     + m_dossierCourant.TailleÉlément + BORDURE_INFOS);
                    }
                }

                // Si on double clique sur la flèche suppérieure
                if (m_dossierCourant.SousDossier)
                {
                    int       posFlècheHaut = Screen.PrimaryScreen.WorkingArea.Width / 2 - 200;
                    Rectangle recFlèche     = new Rectangle(posFlècheHaut, 12, 400, 50);
                    recFlèche.Location = new Point(posFlècheHaut, 12);
                    if (recFlèche.IntersectsWith(recSouris))
                    {
                        m_dossierCourant = m_dossierCourant.Parent;
                        m_dossierCourant.FaireMiseEnPage();
                        Refresh();
                    }
                }
                // Si on double clique sur la flèche droite
                if (!m_dossierCourant.DernierePage())
                {
                    int       posFlècheDroite = Screen.PrimaryScreen.WorkingArea.Height / 2 - 200;
                    Rectangle recFlèche       = new Rectangle(Screen.PrimaryScreen.WorkingArea.Width - 62,
                                                              posFlècheDroite, 50, 400);
                    recFlèche.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - 62,
                                                   posFlècheDroite);
                    if (recFlèche.IntersectsWith(recSouris))
                    {
                        ++m_dossierCourant.IndicePage;
                        m_dossierCourant.FaireMiseEnPage();
                        Refresh();
                    }
                }
                // Si on double clique sur la flèche gauche
                if (m_dossierCourant.IndicePage > 0)
                {
                    int       posFlècheGauche = Screen.PrimaryScreen.WorkingArea.Height / 2 - 200;
                    Rectangle recFlèche       = new Rectangle(12, posFlècheGauche, 50, 400);
                    recFlèche.Location = new Point(12, posFlècheGauche);
                    if (recFlèche.IntersectsWith(recSouris))
                    {
                        --m_dossierCourant.IndicePage;
                        m_dossierCourant.FaireMiseEnPage();
                        Refresh();
                    }
                }
            }
            else if (!m_imageEstMaximisé)
            {
                m_menuContextuel.Show(this, new Point(e.X, e.Y));

                // On envoi à l'objet m_impression le dossier contenant les infos à imprimer
                m_impression.SetDossierImprimer(m_dossierCourant);
            }
            else
            {
                // Un clic droit permet de reculer (toujours pratique)
                if (e.Button == MouseButtons.Right)
                {
                    DessinerImageMaximisée(m_dossierCourant.ObtenirImagePrécédente());
                }
                else
                {
                    DessinerImageMaximisée(m_dossierCourant.ObtenirProchaineImage());
                }
            }
        }