bn2vs
Terugkerende gebruiker
- Lid geworden
- 18 aug 2007
- Berichten
- 1.705
ik heb een fading script in vb.net gemaakt, maar tis een beetje lang (110 lijne), en kan maar door 1 object tegelijk worden gebruikt 
kan iemand ff zien of dit niet beter kan?

kan iemand ff zien of dit niet beter kan?
PHP:
Public Class Form1
Dim mR, mStepR, mG, mStepG, mB, mStepB, thisStep As Integer, objNumber As Integer = 0
Dim fadeIsEnabled As Boolean = False
Const totalSteps As Integer = 10 'set number of steps
Const totalTime As Integer = 100 'set time for each step in ms
Public Sub New()
InitializeComponent()
timerFade.Interval = totalTime : timerFade.Enabled = True
End Sub
Private Sub InitiateFade()
Dim wColorActual, wColorBG, wRAct, wGAct, wBAct, wRFin, wGFin, wBFin As Integer
'retrieve color values
If objNumber = 1 Then wColorActual = Text1.ForeColor.ToArgb() : wColorBG = Text1.BackColor.ToArgb()
If objNumber = 2 Then wColorActual = Text2.ForeColor.ToArgb() : wColorBG = Text2.BackColor.ToArgb()
'process to RGB
ColorToRGB(wColorActual, wRAct, wGAct, wBAct)
ColorToRGB(wColorBG, wRFin, wGFin, wBFin)
'calculate steps
mStepR = CInt((wRAct - wRFin) / totalSteps)
mStepG = CInt((wGAct - wGFin) / totalSteps)
mStepB = CInt((wBAct - wBFin) / totalSteps)
'local to global
mR = wRAct : mG = wGAct : mB = wBAct
'reset and enable
thisStep = 0
fadeIsEnabled = True
End Sub
Private Sub fadeWhileTimerTicks(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles timerFade.Tick
fadeTheStuff()
End Sub
Private Sub ColorToRGB(ByVal Color As Integer, ByRef R As Integer, _
ByRef G As Integer, ByRef B As Integer)
Dim SStr, sR, sG, sB As String
On Error GoTo Hell
'convert integer to hex
SStr = "000000" & Microsoft.VisualBasic.Conversion.Hex(Color)
SStr = Microsoft.VisualBasic.Right(SStr, 6)
'isolate individual colors
sB = "&H" & Mid(SStr, 1, 2) : B = CInt(Format(sB))
sG = "&H" & Mid(SStr, 3, 2) : G = CInt(Format(sG))
sR = "&H" & Mid(SStr, 5, 2) : R = CInt(Format(sR))
Hell:
If Err.Number <> 0 Then
'set vars when error occurs
R = -1 : G = -1 : B = -1
End If
End Sub
Private Sub fadeTheStuff()
Dim isLastStep As Boolean = False, thisColor As System.Drawing.Color
If Not fadeIsEnabled Then Exit Sub
thisStep += 1
isLastStep = thisStep = totalSteps
If isLastStep Then
fadeIsEnabled = False
'set object list
If objNumber = 1 Then Text1.ForeColor = Text1.BackColor
If objNumber = 2 Then Text2.ForeColor = Text2.BackColor
Exit Sub
End If
mR = mR - mStepR : mG = mG - mStepG : mB = mB - mStepB
thisColor = Color.FromArgb(1, mR, mG, mB)
'set object list
If objNumber = 1 Then Text1.ForeColor = thisColor
If objNumber = 2 Then Text2.ForeColor = thisColor
End Sub
Private Sub btnFade1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnFade1.Click
objNumber = 1 : InitiateFade()
End Sub
Private Sub btnFade2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFade2.Click
objNumber = 2 : InitiateFade()
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnReset.Click
Text1.ForeColor = Color.Black
Text2.ForeColor = Color.Black
End Sub
End Class