Il est possible de faire varier l'intensité de la couleur avec une
boucle sur le RGB(1,2,3), mais y a-t-il une API, car en fait, je simule un
voyant sur un bouton, et suivant l'appui sur le bouton (alternat "not"), le
voyant (qui est un TextBox) prend le rouge ou la couleur du bouton, or quand
il est rouge, pour attirer l'attention j'aurais aimé mettre une variation
d'intensité, ce qui m'aurait peut être évité un timer ?
--
Merci, @+, bye, Joe
montmartre75 AROBASE iFrance POINT com
------------------------------------------
Ce message est certifié "plein de virus"
Le_Troll, éleveur de Trolls depuis César, qui disait:
Avec une hache, celui qui tient le manche a toujours raison !
------------------------------------------
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Zoury
Salut Joe!
Ce serait possible mais, étant donnée que VB n'est *pas* multithread, il est pratiquemment impossible de faire de quelque chose de beau *et* d'utilisable sans utiliser timer.. :OP
Voici un exemple, démarre un projet contenant un Form et un Module : '*** Option Explicit
Private m_bIsAnimated As Boolean
Private Sub Command1_Click()
If (Not m_bIsAnimated) Then Call StartControlAnimation(Command1, Me) Command1.Caption = "&Stop" m_bIsAnimated = True Else Call StopControlAnimation Command1.Caption = "&Start" m_bIsAnimated = False End If
End Sub
Private Sub Form_Load() Command1.Caption = "&Start" End Sub
Private Sub Form_Unload(Cancel As Integer) If (m_bIsAnimated) Then Call StopControlAnimation End If End Sub '***
'*** ' Module1 Option Explicit
Private Declare Function SetTimer _ Lib "user32" _ ( _ ByVal hWnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long _ ) As Long
Private Declare Function KillTimer _ Lib "user32" _ ( _ ByVal hWnd As Long, _ ByVal nIDEvent As Long _ ) As Long
Private Declare Sub CopyMemory _ Lib "kernel32" _ Alias "RtlMoveMemory" _ ( _ ByRef pDst As Any, _ ByRef pSrc As Any, _ ByVal ByteLen As Long _ )
Private Type tColor r As Byte g As Byte b As Byte End Type
Private m_ctl As Control Private m_frm As Form Private Const TOLERANCE_PCT As Single = 1 / 2 ' 50%
Public Sub TimerProc _ ( _ ByVal hWnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long _ )
Static c As tColor Static bUp As Boolean Static bStarted As Boolean
' vérifie si la propriété BackColor ' existent sur le contrôle.. ' sinon on quitte On Error Resume Next m_ctl.BackColor = m_ctl.BackColor If (Err.Number > 0) Then ' le controle m'a pas de propriété BackColor.. Call StopControlAnimation m_ctl.Caption = "&Start" Exit Sub End If On Error GoTo 0
' le premier coup on retourve ' la couleur du contrôle If (Not bStarted) Then c = GetColorFromLong(m_ctl.BackColor) bStarted = True End If
' modifie la couleur de fond If (Not bUp) Then If (c.r > 0) Then c.r = c.r - 1 Else bUp = True End If Else If (c.r < 255) Then c.r = c.r + 1 Else bUp = False End If End If m_ctl.BackColor = RGB(c.r, c.g, c.b)
'OPTIONNEL!! ' Pour les contrôles ayant un ForeColor, ' nous ferons varier la couleur du ' texte de noir à blanc afin de toujours ' pouvoir bien lire le texte peu ' importe le BackColor en cours.. ' ' vérifie si la propriété ForeColor ' existent sur le contrôle.. ' sinon on ne change rien On Error Resume Next m_ctl.ForeColor = m_ctl.ForeColor If (Err.Number = 0) Then ' modifie le texte en fonction de la couleur de fond ' Change la couleur du texte en fonction du background... ' on peut modifier la tolérance, mais 50% donne ' le meilleur effet AMHA.. If (c.r + c.g + c.b) > ((255 * 3) * TOLERANCE_PCT) Then m_ctl.ForeColor = vbBlack Else m_ctl.ForeColor = vbWhite End If End If
End Sub
Public Sub StartControlAnimation(ByRef ctl As Control, ByRef frmOwner As Form) Set m_ctl = ctl Set m_frm = frmOwner Call SetTimer(m_frm.hWnd, 0, 10, AddressOf TimerProc) End Sub
Public Sub StopControlAnimation() Call KillTimer(m_frm.hWnd, 0) End Sub
Private Function GetColorFromLong(ByRef lColor As Long) As tColor Call CopyMemory(GetColorFromLong, lColor, 3) End Function '***
Ce serait possible mais, étant donnée que VB n'est *pas* multithread, il est
pratiquemment impossible de faire de quelque chose de beau *et* d'utilisable
sans utiliser timer.. :OP
Voici un exemple, démarre un projet contenant un Form et un Module :
'***
Option Explicit
Private m_bIsAnimated As Boolean
Private Sub Command1_Click()
If (Not m_bIsAnimated) Then
Call StartControlAnimation(Command1, Me)
Command1.Caption = "&Stop"
m_bIsAnimated = True
Else
Call StopControlAnimation
Command1.Caption = "&Start"
m_bIsAnimated = False
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "&Start"
End Sub
Private Sub Form_Unload(Cancel As Integer)
If (m_bIsAnimated) Then
Call StopControlAnimation
End If
End Sub
'***
'***
' Module1
Option Explicit
Private Declare Function SetTimer _
Lib "user32" _
( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long _
) As Long
Private Declare Function KillTimer _
Lib "user32" _
( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long _
) As Long
Private Declare Sub CopyMemory _
Lib "kernel32" _
Alias "RtlMoveMemory" _
( _
ByRef pDst As Any, _
ByRef pSrc As Any, _
ByVal ByteLen As Long _
)
Private Type tColor
r As Byte
g As Byte
b As Byte
End Type
Private m_ctl As Control
Private m_frm As Form
Private Const TOLERANCE_PCT As Single = 1 / 2 ' 50%
Public Sub TimerProc _
( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long _
)
Static c As tColor
Static bUp As Boolean
Static bStarted As Boolean
' vérifie si la propriété BackColor
' existent sur le contrôle..
' sinon on quitte
On Error Resume Next
m_ctl.BackColor = m_ctl.BackColor
If (Err.Number > 0) Then
' le controle m'a pas de propriété BackColor..
Call StopControlAnimation
m_ctl.Caption = "&Start"
Exit Sub
End If
On Error GoTo 0
' le premier coup on retourve
' la couleur du contrôle
If (Not bStarted) Then
c = GetColorFromLong(m_ctl.BackColor)
bStarted = True
End If
' modifie la couleur de fond
If (Not bUp) Then
If (c.r > 0) Then
c.r = c.r - 1
Else
bUp = True
End If
Else
If (c.r < 255) Then
c.r = c.r + 1
Else
bUp = False
End If
End If
m_ctl.BackColor = RGB(c.r, c.g, c.b)
'OPTIONNEL!!
' Pour les contrôles ayant un ForeColor,
' nous ferons varier la couleur du
' texte de noir à blanc afin de toujours
' pouvoir bien lire le texte peu
' importe le BackColor en cours..
'
' vérifie si la propriété ForeColor
' existent sur le contrôle..
' sinon on ne change rien
On Error Resume Next
m_ctl.ForeColor = m_ctl.ForeColor
If (Err.Number = 0) Then
' modifie le texte en fonction de la couleur de fond
' Change la couleur du texte en fonction du background...
' on peut modifier la tolérance, mais 50% donne
' le meilleur effet AMHA..
If (c.r + c.g + c.b) > ((255 * 3) * TOLERANCE_PCT) Then
m_ctl.ForeColor = vbBlack
Else
m_ctl.ForeColor = vbWhite
End If
End If
End Sub
Public Sub StartControlAnimation(ByRef ctl As Control, ByRef frmOwner As
Form)
Set m_ctl = ctl
Set m_frm = frmOwner
Call SetTimer(m_frm.hWnd, 0, 10, AddressOf TimerProc)
End Sub
Public Sub StopControlAnimation()
Call KillTimer(m_frm.hWnd, 0)
End Sub
Private Function GetColorFromLong(ByRef lColor As Long) As tColor
Call CopyMemory(GetColorFromLong, lColor, 3)
End Function
'***
Ce serait possible mais, étant donnée que VB n'est *pas* multithread, il est pratiquemment impossible de faire de quelque chose de beau *et* d'utilisable sans utiliser timer.. :OP
Voici un exemple, démarre un projet contenant un Form et un Module : '*** Option Explicit
Private m_bIsAnimated As Boolean
Private Sub Command1_Click()
If (Not m_bIsAnimated) Then Call StartControlAnimation(Command1, Me) Command1.Caption = "&Stop" m_bIsAnimated = True Else Call StopControlAnimation Command1.Caption = "&Start" m_bIsAnimated = False End If
End Sub
Private Sub Form_Load() Command1.Caption = "&Start" End Sub
Private Sub Form_Unload(Cancel As Integer) If (m_bIsAnimated) Then Call StopControlAnimation End If End Sub '***
'*** ' Module1 Option Explicit
Private Declare Function SetTimer _ Lib "user32" _ ( _ ByVal hWnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long _ ) As Long
Private Declare Function KillTimer _ Lib "user32" _ ( _ ByVal hWnd As Long, _ ByVal nIDEvent As Long _ ) As Long
Private Declare Sub CopyMemory _ Lib "kernel32" _ Alias "RtlMoveMemory" _ ( _ ByRef pDst As Any, _ ByRef pSrc As Any, _ ByVal ByteLen As Long _ )
Private Type tColor r As Byte g As Byte b As Byte End Type
Private m_ctl As Control Private m_frm As Form Private Const TOLERANCE_PCT As Single = 1 / 2 ' 50%
Public Sub TimerProc _ ( _ ByVal hWnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long _ )
Static c As tColor Static bUp As Boolean Static bStarted As Boolean
' vérifie si la propriété BackColor ' existent sur le contrôle.. ' sinon on quitte On Error Resume Next m_ctl.BackColor = m_ctl.BackColor If (Err.Number > 0) Then ' le controle m'a pas de propriété BackColor.. Call StopControlAnimation m_ctl.Caption = "&Start" Exit Sub End If On Error GoTo 0
' le premier coup on retourve ' la couleur du contrôle If (Not bStarted) Then c = GetColorFromLong(m_ctl.BackColor) bStarted = True End If
' modifie la couleur de fond If (Not bUp) Then If (c.r > 0) Then c.r = c.r - 1 Else bUp = True End If Else If (c.r < 255) Then c.r = c.r + 1 Else bUp = False End If End If m_ctl.BackColor = RGB(c.r, c.g, c.b)
'OPTIONNEL!! ' Pour les contrôles ayant un ForeColor, ' nous ferons varier la couleur du ' texte de noir à blanc afin de toujours ' pouvoir bien lire le texte peu ' importe le BackColor en cours.. ' ' vérifie si la propriété ForeColor ' existent sur le contrôle.. ' sinon on ne change rien On Error Resume Next m_ctl.ForeColor = m_ctl.ForeColor If (Err.Number = 0) Then ' modifie le texte en fonction de la couleur de fond ' Change la couleur du texte en fonction du background... ' on peut modifier la tolérance, mais 50% donne ' le meilleur effet AMHA.. If (c.r + c.g + c.b) > ((255 * 3) * TOLERANCE_PCT) Then m_ctl.ForeColor = vbBlack Else m_ctl.ForeColor = vbWhite End If End If
End Sub
Public Sub StartControlAnimation(ByRef ctl As Control, ByRef frmOwner As Form) Set m_ctl = ctl Set m_frm = frmOwner Call SetTimer(m_frm.hWnd, 0, 10, AddressOf TimerProc) End Sub
Public Sub StopControlAnimation() Call KillTimer(m_frm.hWnd, 0) End Sub
Private Function GetColorFromLong(ByRef lColor As Long) As tColor Call CopyMemory(GetColorFromLong, lColor, 3) End Function '***