commandbutton moussemove

axou91

XLDnaute Nouveau
Bonjour à tous,

Je viens vers vous car je bute sur un problème. J'ai deux commandbuttons. Quand la souris est sur un commandbutton, le forecolor deviens blanc et l'autre reste noir. J'aimerai (mais je ne sais pas comment faire) que lorsque la souris sort de l'espace du commandbutton le forecolor reprenne sa couleur originale.

Je vous ai mis un exemple en pièce jointe.

Merci pour votre aide.

Axou
 

Pièces jointes

  • exemple.xlsm
    21.1 KB · Affichages: 45
  • exemple.xlsm
    21.1 KB · Affichages: 42
  • exemple.xlsm
    21.1 KB · Affichages: 38

phlaurent55

Nous a quittés en 2020
Repose en paix
Re : commandbutton moussemove

Bonjour axou,

voir fichier joint
j'ai modifié la procédure pour "une sortie de bouton à la verticale"
reste à faire pour une "sortie horizontale" ( en fonction de X )

à+
Philippe
 

Pièces jointes

  • 111.xlsm
    19.8 KB · Affichages: 30
  • 111.xlsm
    19.8 KB · Affichages: 36
  • 111.xlsm
    19.8 KB · Affichages: 32

Lolote83

XLDnaute Barbatruc
Re : commandbutton moussemove

Salut, peut être comme ca:

Code:
Const xBlanc = &HFFFFFF
Const xNoir = &H80000012

Private Sub CommandButton1_LostFocus()
    CommandButton2.ForeColor = xBlanc
    CommandButton1.ForeColor = xBlanc
End Sub

Private Sub CommandButton2_LostFocus()
    CommandButton2.ForeColor = xBlanc
    CommandButton1.ForeColor = xBlanc
End Sub

Private Sub commandbutton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    CommandButton1.ForeColor = xNoir
    CommandButton2.ForeColor = xBlanc
End Sub

Private Sub commandbutton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    CommandButton2.ForeColor = xNoir
    CommandButton1.ForeColor = xBlanc
End Sub
Ou l'inverse si je me suis trompé dans l'affectation des couleurs
@+ Lolote83
 

laetitia90

XLDnaute Barbatruc
Re : commandbutton moussemove

bonjour tous

autre methode

Code:
Private Sub commandbutton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
 With CommandButton1
 .ForeColor = IIf(X > 15 And X < .Width + 15 And Y > 15 And Y < .Height + 15, &HFFFFFF, &H80000012)
 End With
End Sub
Private Sub commandbutton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
 With CommandButton2
 .ForeColor = IIf(X > 15 And X < .Width + 15 And Y > 15 And Y < .Height + 15, &H80000012, &HFFFFFF)
 End With
End Sub

le bouton 2 plus grand met 30 a la place de 15 variable x & y
 
Dernière édition:

axou91

XLDnaute Nouveau
Re : commandbutton moussemove

Bonjour et merci pour votre aide,

Je veux pas faire mon reloud de service mais...... ca ne marche pas......
Laetitia, je n'ai pas essayé ta méthode car mes boutons sont de la même dimension. Dans mon fichier exemple, il s'agit d'un exemple.

Désolé.
 

laetitia90

XLDnaute Barbatruc
Re : commandbutton moussemove

re ,
j'ai mis 30 pour "affiner" il y a .Height & .Width du com...pas de pb...
pour ceux que cela interesse une piste avec une tempo..... pas finaliser mais bon!!!!

Code:
Private Sub commandbutton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    CommandButton1.ForeColor = &H80000012
    S = Timer: Do While Timer < S + 0.8: DoEvents: Loop
    CommandButton1.ForeColor = &HFFFFFF
End Sub
 

Discussions similaires

Réponses
6
Affichages
746

Statistiques des forums

Discussions
312 249
Messages
2 086 600
Membres
103 256
dernier inscrit
Melomaniak