Partage
  • Partager sur Facebook
  • Partager sur Twitter

Mon code ne marche pas ..

If avec une location ..

    11 août 2011 à 19:21:33

    Vous l'aurez remarqué je ne suis pas du tout à l'aise avec les locations et j'aimerai faire cela : "
    Si la location de ma picture Box = 123 , 123 alors [Blabla] .."
    Mon code :

    If MapictureBox.Location = New point(123 , 123) Then 
    [Blabla]
    End if
    


    Comment dois-je faire , je ne dois pas mettre nex point ? Je ne sais pas , aidez moi s'il vous plaît !!
    • Partager sur Facebook
    • Partager sur Twitter
      11 août 2011 à 20:22:15

      Il suffit de définir un objet point au préalable.
      Par exemple :
      Point monObjetPoint = new Point();
      // ... Tes opérations sur l'objet...
      if (MapictureBox.Location == monObjetPoint)
      {
      //...
      }
      
      • Partager sur Facebook
      • Partager sur Twitter
        11 août 2011 à 22:48:37

        Je pensais qu'un seul = produisait une erreur parce qu'en C# il en faut deux ; mais apparemment en VB.NET, ce n'est pas le cas.

        Mon post est donc à supprimer. Merci. :-°
        • Partager sur Facebook
        • Partager sur Twitter
          12 août 2011 à 7:50:12

          Citation : OrionPyro

          Il suffit de définir un objet point au préalable.
          Par exemple :

          Point monObjetPoint = new Point();
          // ... Tes opérations sur l'objet...
          if (MapictureBox.Location == monObjetPoint)
          {
          //...
          }
          

          Et si je ne désire pas passer par une variables ?
          Parceque en fait c'est un if sur 5 - 6 locations .. donc il me faudrait 5 - 6 variables .
          • Partager sur Facebook
          • Partager sur Twitter
            12 août 2011 à 8:36:20

            Je te conseille de creer une fonction pour cela ... de la maniere suivante

            static void Main(string[] args)
                    {
                        var p1 = new Personne { Nom = "fred", Age = 30 };
                        var p2 = new Personne { Nom = "victore", Age = 25 };
                        Console.WriteLine(ComparePersonne(p1,p2).ToString());
                        Console.WriteLine(ComparePersonne(new Personne { Nom = "victore", Age = 25 }, p2).ToString());
                        Console.ReadLine();
                    }
            
            
                    static bool ComparePersonne(Personne p1, Personne p2) {
                        return (p1.Nom.Equals(p2.Nom) && p1.Age == p2.Age);
                    }
            
                    public class Personne
                    {
                        public string Nom { get; set; }
                        public int Age { get; set; }
                    }
            


            Ce code marche parfaitement et t'evite de creer 200 variables et ca retourne le bon resultat :)
            • Partager sur Facebook
            • Partager sur Twitter
              12 août 2011 à 8:41:05

              if MaPictureBox.location.X = 123 and MapictureBox.location.Y = 12 then
              Me.BT_1.enabled = true

              End if
              </code>

              Quesqu'y ne marche pas ?

              Me.MONTER.Enabled = False
              
              
                      Loc_X = PIctureBox.Location.X
                      If Loc_X = 218 Or 219 Or 220 Or 221 Or 222 Or 223 Or 224 Or 225 Or 227 Or 228 Or 226 Then
                          Me.MONTER.Enabled = True
                      End If
              
              • Partager sur Facebook
              • Partager sur Twitter
                12 août 2011 à 11:52:03

                Citation : -G-


                Quesqu'y ne marche pas ?

                Loc_X = PIctureBox.Location.X
                        If Loc_X = 218 Loc_X = Or Loc_X = 219 Or Loc_X = 220 Or Loc_X = 221 Or Loc_X = 222 Or Loc_X = 223 Or Loc_X = 224 Or Loc_X = 225 Or Loc_X = 227 Or Loc_X = 228 Or Loc_X = 226 Then
                            Me.MONTER.Enabled = True
                        End If
                

                Mais bon franchement c'est moche, pourquoi ne pas utiliser les signe < et >?
                Loc_X = PIctureBox.Location.X
                        If Loc_X > 217  AND Loc_X < 227 Then
                            Me.MONTER.Enabled = True
                        End If
                

                ca serait bien que tu travailles davantage la syntaxe du vb quand même ... (bon perso je programme pas en vb, mais bon si je devais le faire j'étudierais un peu plus comment ca s'écrit...)
                • Partager sur Facebook
                • Partager sur Twitter
                ** La doc, c'est comme le PQ: ça sert à se démerder tout seul **
                  12 août 2011 à 12:59:33

                  Qui peux m'aider en message privée , j'ai réellement un gros problème !
                  • Partager sur Facebook
                  • Partager sur Twitter
                    12 août 2011 à 13:09:59

                    Avec une location elle-même non, mais avec la propriété X comme montré ici ça l'est puisque le champ est un nombre. (Cela vaut évidemment aussi pour Y)
                    • Partager sur Facebook
                    • Partager sur Twitter
                      12 août 2011 à 13:14:35

                      Mon code semble bon , regardez :
                      Dim Loc_Y As Integer
                          Dim Loc_X As Integer
                      
                          Private Sub YugoBros_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                      
                              Me.MONTER.Enabled = False
                      
                              Loc_X = Tristepin.Location.X
                              Loc_Y = Tristepin.Location.Y
                      
                      
                              Loc_X = Tristepin.Location.X
                              If Loc_X > 245 And Loc_X < 275 And Loc_Y = 163 Then
                                  Me.MONTER.Enabled = True
                              End If
                      
                      
                      
                      
                      
                          End Sub
                      
                          Private Sub Gauche_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GAUCHE.Click
                              Me.Tristepin2.Visible = False
                              Me.Tristepin.Visible = True
                              Tristepin.Location = New Point(Tristepin.Location.X + 3, Tristepin.Location.Y)
                              Tristepin2.Location = New Point(Tristepin.Location.X + 3, Tristepin.Location.Y)
                          End Sub
                          Private Sub Monter_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MONTER.Click
                      
                              Me.Tristepin2.Visible = False
                              Me.Tristepin.Visible = True
                              Tristepin.Location = New Point(Tristepin.Location.X, Tristepin.Location.Y - 2)
                              Tristepin2.Location = New Point(Tristepin.Location.X, Tristepin.Location.Y - 2)
                          End Sub
                      
                      
                          Private Sub DESCENDRE_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DESCENDRE.Click
                              Me.Tristepin2.Visible = False
                              Me.Tristepin.Visible = True
                              Tristepin.Location = New Point(Tristepin.Location.X, Tristepin.Location.Y + 2)
                              Tristepin.Location = New Point(Tristepin.Location.X, Tristepin.Location.Y + 2)
                          End Sub
                          Private Sub Droite_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DROITE.Click
                              Me.Tristepin2.Visible = True
                              Me.Tristepin.Visible = False
                              Tristepin.Location = New Point(Tristepin.Location.X - 2, Tristepin.Location.Y)
                              Tristepin2.Location = New Point(Tristepin.Location.X - 2, Tristepin.Location.Y)
                          End Sub
                      
                      
                      End Class
                      


                      et quand je lance et que j'arrive à la location désirée :
                      Image utilisateur
                      vous remarquerez que le bouton Monter et toujours inutilisable alors que je suissur la location voule.. porquoi ?
                      • Partager sur Facebook
                      • Partager sur Twitter
                        12 août 2011 à 13:23:57

                        C'est parce que la condition qui active le bouton "Monter" n'est appelée qu'au chargement de la fenêtre (Private Sub YugoBros_Load)
                        Il faut lancer une boucle qui vérifie à chaque frame ceci :
                        If Loc_X > 245 And Loc_X < 275 And Loc_Y = 163 Then
                                    Me.MONTER.Enabled = True
                                End If
                        
                        • Partager sur Facebook
                        • Partager sur Twitter
                          12 août 2011 à 13:25:09

                          Merci beaucoup , OrionPyro !
                          • Partager sur Facebook
                          • Partager sur Twitter
                            12 août 2011 à 13:27:12

                            [HS] Ce serait mieux si tu pouvais mettre un titre convenable au sujet. [/HS]

                            [Edit] : la meme qu'orion. Il etait plus rapide.


                            Il faut le placer dans une fonction qui sera appelée à chaque fois que ta picture box bouge.
                            Dans ton cas si j'ai bien compris : dans tes fonctions Gauche Droite Monter et descendre click de la maniere suivante

                            Private Sub Gauche_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GAUCHE.Click
                                    Me.Tristepin2.Visible = False
                                    Me.Tristepin.Visible = True
                                    Tristepin.Location = New Point(Tristepin.Location.X + 3, Tristepin.Location.Y)
                                    Tristepin2.Location = New Point(Tristepin.Location.X + 3, Tristepin.Location.Y)
                                    If Loc_X > 245 And Loc_X < 275 And Loc_Y = 163 Then
                                        Me.MONTER.Enabled = True
                                    End If
                                End Sub
                                Private Sub Monter_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MONTER.Click
                            
                                    Me.Tristepin2.Visible = False
                                    Me.Tristepin.Visible = True
                                    Tristepin.Location = New Point(Tristepin.Location.X, Tristepin.Location.Y - 2)
                                    Tristepin2.Location = New Point(Tristepin.Location.X, Tristepin.Location.Y - 2)
                                    If Loc_X > 245 And Loc_X < 275 And Loc_Y = 163 Then
                                        Me.MONTER.Enabled = True
                                    End If
                                End Sub
                            
                            
                                Private Sub DESCENDRE_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DESCENDRE.Click
                                    Me.Tristepin2.Visible = False
                                    Me.Tristepin.Visible = True
                                    Tristepin.Location = New Point(Tristepin.Location.X, Tristepin.Location.Y + 2)
                                    Tristepin.Location = New Point(Tristepin.Location.X, Tristepin.Location.Y + 2)
                                    If Loc_X > 245 And Loc_X < 275 And Loc_Y = 163 Then
                                        Me.MONTER.Enabled = True
                                    End If
                                End Sub
                                Private Sub Droite_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DROITE.Click
                                    Me.Tristepin2.Visible = True
                                    Me.Tristepin.Visible = False
                                    Tristepin.Location = New Point(Tristepin.Location.X - 2, Tristepin.Location.Y)
                                    Tristepin2.Location = New Point(Tristepin.Location.X - 2, Tristepin.Location.Y)
                                    If Loc_X > 245 And Loc_X < 275 And Loc_Y = 163 Then
                                        Me.MONTER.Enabled = True
                                    End If
                                End Sub
                            
                            • Partager sur Facebook
                            • Partager sur Twitter
                              12 août 2011 à 13:28:39

                              Ok , merci . Faut que je trouve comment faire >_< !
                              La fonction LocationChanged marcherai ?
                              PS : Merci ça marche !
                              • Partager sur Facebook
                              • Partager sur Twitter

                              Mon code ne marche pas ..

                              × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                              × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                              • Editeur
                              • Markdown