IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

Probleme entre les Forms


Sujet :

Windows Forms

  1. #1
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut Probleme entre les Forms
    Salut a tous ,
    SVP j'ai un petit probleme si quelqu'un pourrait m'aider , j'ai realisé une petite application qui contient plusieurs Forms ,
    -je veux que si j'appel une Form ; je ne peux pas toucher la premiere et si c'est possible elle devient sombre (la 1ere).
    -meme je permet pas la navigation entre Forms avec (Alt+Tab) et la sortie Avec (Alt+F4).
    merci d'avance.

  2. #2
    Rédacteur
    Avatar de Paul Musso
    Profil pro
    Inscrit en
    Août 2008
    Messages
    368
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Août 2008
    Messages : 368
    Points : 443
    Points
    443
    Par défaut
    Bonjour Bellak,

    Tout d'abord, pour que ta fenêtre soit modale utilise le code suivant pour l'ouvrir :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Form2 form = new Form2();
    form.ShowDialog();
    Remplace bien sûr "Form2" par la classe de ta fenêtre ^^

    Ensuite, pour désactiver la navigation, assigne sa variable ShowInTaskbar à false.

    Finalement, pour empêcher la fermeture de la fenêtre avec un Alt + F4, ajoute une méthode à l'évènement FormClosing et définit la propriété Cancel de la variable FormClosingEventArgs à false, voici un exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
         e.Cancel = false;
    }
    Finallement pour la couleur de fond de ta fenêtre hôte, redéfinie la quand tu ouvre ta 2ème fenêtre, et retaure là lors de sa fermeture.

  3. #3
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    Citation Envoyé par Paul Musso Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
         e.Cancel = false;
    }
    A true, tu veux dire.

    Par contre, avec un code comme ça, il est impossible de fermer l'application

  4. #4
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut
    Salut tt le monde ,
    pour les deux premieres reponses de "Paul Musso" ça marche tres bien mais pour la troisieme comme "Jerome" a dit impossible de fermer l'application .
    et pour l'autre probleme (enfin c'est pas un vraie probleme) je veux pas que la couleur du fond change , je veux que tt ce qui est en dessous de la fenetre devient sombre .
    Merci .

  5. #5
    Rédacteur
    Avatar de Paul Musso
    Profil pro
    Inscrit en
    Août 2008
    Messages
    368
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Août 2008
    Messages : 368
    Points : 443
    Points
    443
    Par défaut
    Oui autant pour moi pour le true, et c'est vrai que ça bloque tout du coup.

    Le mieux est d'ajouter une méthode sur l'évènement KeyDown de ta fenêtre, de ce genre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    private void Form2_KeyDown(object sender, KeyEventArgs e)
    {
      if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.F4)
          e.Handled = true;
    }
    Après pour griser toute l'interface derrière, je sais pas vraiment ...

  6. #6
    En attente de confirmation mail
    Inscrit en
    Août 2006
    Messages
    550
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Août 2006
    Messages : 550
    Points : 669
    Points
    669
    Par défaut
    Pour griser un écran je peux te proposer une astuce que j'avais utiliser une fois.
    Le "grisage" s'effectue lorsqu'on clique sur le bouton de la fenetre.
    Tu peux créer ta propre "form" avec ces fonctionnalités et faire hériter tes fenetre de cette "form".


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
     
        Private mBln_Griser As Boolean = False
        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            mBln_Griser = Not mBln_Griser
            Me.InvalidateAll(Me)
        End Sub
        Private Sub InvalidateAll( _
            ByVal objControl As Control _
        )
            For Each objChildCtrl As Control In objControl.Controls
                InvalidateAll(objChildCtrl)
            Next
            objControl.Invalidate()
        End Sub
        Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
            MyBase.OnLoad(e)
            AddHandlerControlPaint(Me)
        End Sub
        Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
            MyBase.OnClosed(e)
            RemoveHandlerControlPaint(Me)
        End Sub
        Private Sub AddHandlerControlPaint( _
            ByVal objControl As Control _
        )
            For Each objChildCtrl As Control In objControl.Controls
                AddHandlerControlPaint(objChildCtrl)
            Next
            AddHandler objControl.Paint, AddressOf Control_Paint
        End Sub
        Private Sub RemoveHandlerControlPaint( _
            ByVal objControl As Control _
        )
            For Each objChildCtrl As Control In objControl.Controls
                RemoveHandlerControlPaint(objChildCtrl)
            Next
            RemoveHandler objControl.Paint, AddressOf Control_Paint
        End Sub
        Protected Sub Control_Paint( _
            ByVal sender As Object, _
            ByVal e As System.Windows.Forms.PaintEventArgs _
        )
            If mBln_Griser Then GriserEcran(e.Graphics, sender)
        End Sub
        Private Sub GriserEcran( _
            ByVal objGraphics As Graphics, _
            ByVal objControl As Control _
        )
            Dim objBitmap As Image = New Bitmap(objControl.Width, objControl.Height, Imaging.PixelFormat.Format32bppArgb)
            Dim objGraph As Graphics = Graphics.FromImage(objBitmap)
            objGraph.Clear(Color.Black)
            Dim objColorMatrix As New Imaging.ColorMatrix
            objColorMatrix.Matrix33 = 0.25
            Dim objImageAttributes As New Imaging.ImageAttributes
            objImageAttributes.SetColorMatrix( _
                objColorMatrix _
            )
            objGraphics.DrawImage( _
                objBitmap, objControl.ClientRectangle, _
                0, 0, objBitmap.Width, objBitmap.Height, GraphicsUnit.Pixel, objImageAttributes _
            )
        End Sub

  7. #7
    En attente de confirmation mail
    Inscrit en
    Août 2006
    Messages
    550
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Août 2006
    Messages : 550
    Points : 669
    Points
    669
    Par défaut
    Pour la version c#

    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    private bool mBln_Griser = false; 
    private void Button1_Click(object sender, System.EventArgs e) 
    { 
        mBln_Griser = !mBln_Griser; 
        this.InvalidateAll(this); 
    } 
    private void InvalidateAll(Control objControl) 
    { 
        foreach (Control objChildCtrl in objControl.Controls) { 
            InvalidateAll(objChildCtrl); 
        } 
        objControl.Invalidate(); 
    } 
    protected override void OnLoad(System.EventArgs e) 
    { 
        base.OnLoad(e); 
        AddHandlerControlPaint(this); 
    } 
    protected override void OnClosed(System.EventArgs e) 
    { 
        base.OnClosed(e); 
        RemoveHandlerControlPaint(this); 
    } 
    private void AddHandlerControlPaint(Control objControl) 
    { 
        foreach (Control objChildCtrl in objControl.Controls) { 
            AddHandlerControlPaint(objChildCtrl); 
        } 
        objControl.Paint += Control_Paint; 
    } 
    private void RemoveHandlerControlPaint(Control objControl) 
    { 
        foreach (Control objChildCtrl in objControl.Controls) { 
            RemoveHandlerControlPaint(objChildCtrl); 
        } 
        objControl.Paint -= Control_Paint; 
    } 
    protected void Control_Paint(object sender, System.Windows.Forms.PaintEventArgs e) 
    { 
        if (mBln_Griser) 
            GriserEcran(e.Graphics, sender); 
    } 
    private void GriserEcran(Graphics objGraphics, Control objControl) 
    { 
        Image objBitmap = new Bitmap(objControl.Width, objControl.Height, Imaging.PixelFormat.Format32bppArgb); 
        Graphics objGraph = Graphics.FromImage(objBitmap); 
        objGraph.Clear(Color.Black); 
        Imaging.ColorMatrix objColorMatrix = new Imaging.ColorMatrix(); 
        objColorMatrix.Matrix33 = 0.25; 
        Imaging.ImageAttributes objImageAttributes = new Imaging.ImageAttributes(); 
        objImageAttributes.SetColorMatrix(objColorMatrix); 
        objGraphics.DrawImage(objBitmap, objControl.ClientRectangle, 0, 0, objBitmap.Width, objBitmap.Height, GraphicsUnit.Pixel, objImageAttributes); 
    }

  8. #8
    Membre éclairé
    Inscrit en
    Octobre 2006
    Messages
    587
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Octobre 2006
    Messages : 587
    Points : 706
    Points
    706
    Par défaut
    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    foreach (Control objChildCtrl in objControl.Controls) { 
            InvalidateAll(objChildCtrl); 
        } 
        objControl.Invalidate();
    La méthode Invalidate possède une surcharge permettant de rafraichir ou non les contrôles enfants...

  9. #9
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut
    Salut a tous ,
    merci pour vos codes , je vais les essayé et dès qu'il sera resulo je met "RESOLU" .

  10. #10
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut
    il y a un petit probleme dans le code de "PAUL" , si la Form ne contient pas des zones de text (TextBox...) ça marche tres bien mais sinon ça fonctionne pas .

  11. #11
    En attente de confirmation mail
    Inscrit en
    Août 2006
    Messages
    550
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Août 2006
    Messages : 550
    Points : 669
    Points
    669
    Par défaut
    Il faut utiliser la propriété KeyPreview de ta form

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    MyForm.KeyPreview = True

  12. #12
    Rédacteur
    Avatar de Paul Musso
    Profil pro
    Inscrit en
    Août 2008
    Messages
    368
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Août 2008
    Messages : 368
    Points : 443
    Points
    443
    Par défaut
    Mon sauveur .

    Oui ça permet de spécifier que les évènements claviers soient d'abord interceptés par la fenêtre.

  13. #13
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut
    re merci "Kelpan" pour le code ,
    Image objBitmap = new Bitmap(objControl.Width, objControl.Height, Imaging.PixelFormat.Format32bppArgb);
    j'etait obligé de mettre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Image objBitmap = new Bitmap(objControl.Width, objControl.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    meme si le namespace est declaré , c'est pas un probleme le vrai probleme c'est au niveau de :
    GriserEcran(e.Graphics, sender);
    cela me donne 2 erreurs :
    *La méthode surchargée correspondant le mieux à 'KryptonFormProject1.Form2.GriserEcran(System.Drawing.Graphics, System.Windows.Forms.Control)' possède des arguments non valides
    *Argument '2' : impossible de convertir de 'object' en 'System.Windows.Forms.Control'
    merci et pardon pour le derangement .

  14. #14
    En attente de confirmation mail
    Inscrit en
    Août 2006
    Messages
    550
    Détails du profil
    Informations personnelles :
    Âge : 49

    Informations forums :
    Inscription : Août 2006
    Messages : 550
    Points : 669
    Points
    669
    Par défaut
    En effet, je code en VB habituellement, le lateBinding est autorisé.

    Tu dois typer correctement tes variables en C#
    si je me souvient bien :

    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    GriserEcran(e.Graphics, (Control)sender);

  15. #15
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut
    Chapeau "Kelpan" , your are the best .
    merci a tous .

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. probleme avec les form
    Par lilsou dans le forum C#
    Réponses: 1
    Dernier message: 08/06/2009, 11h28
  2. [AJAX] Les liens et ajax
    Par sooprano dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 05/03/2009, 18h16
  3. champs comment entre les forms
    Par john_wili dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 27/01/2009, 09h52
  4. navigation entre les forms
    Par winners12 dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 28/04/2007, 23h04
  5. [2.0][C#] Llien entre les forms
    Par croko dans le forum Windows Forms
    Réponses: 7
    Dernier message: 20/11/2006, 15h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo