Yesterday I was fiddling with a progress bar, it was performing step in every single action to show current status.
Worker had several phases so I decided to change the color in every phase which is more eye candy and useful to the user. I implemented color changes but it was not enough cool and then I decided develop a small color transition effect for every phase changes. Here is the code how I accomplish the task;
This process may can slow your application a bit, be careful! and disable lock if you want it faster.
1 : <%
3 : Dim LockObj As New Object
4 : Public Sub PhaseChangedHandler(ByVal sender As Object, ByVal e As EventArguments.PhaseChangedEventArgs)
5 : SyncLock LockObj
6 : Select Case DirectCast(e, EventArguments.PhaseChangedEventArgs).Phase
7 : Case DilemmaManager.Phase.PhaseX
8 : TransColors(PrgMain.ForeColor, Color.DodgerBlue, PrgStatus)
10 : Case DilemmaManager.Phase.Y, DilemmaManager.Phase.Z
11 : TransColors(PrgMain.ForeColor, Color.DeepSkyBlue, PrgStatus)
13 : Case DilemmaManager.Phase.D
14 : TransColors(PrgMain.ForeColor, Color.DeepPink, PrgStatus)
16 : End Select
17 : End SyncLock
19 : End Sub
22 : ''' <summary>
23 : ''' Apply transition effect to progress bar color.
24 : ''' </summary>
25 : ''' <param name="startingColor">Color of the starting.</param>
26 : ''' <param name="endingColor">Color of the ending.</param>
27 : ''' <param name="progressBar">The progress bar.</param>
28 : Private Sub TransColors(ByVal startingColor As Color, ByVal endingColor As Color, ByVal progressBar As ToolStripProgressBar)
30 : Dim R As Integer = startingColor.R
31 : Dim B As Integer = startingColor.B
32 : Dim G As Integer = startingColor.G
34 : While Not (R = endingColor.R AndAlso B = endingColor.B AndAlso G = endingColor.G)
35 : R = StepCloser(R, endingColor.R)
36 : B = StepCloser(B, endingColor.B)
37 : G = StepCloser(G, endingColor.G)
39 : ChangeColor(Color.FromArgb(R, G, B), PrgStatus)
40 : Threading.Thread.Sleep(1)
41 : End While
43 : End Sub
46 :
47 : Const StepSpeed As Integer = 1
49 :
50 : ''' <summary>
51 : ''' One step increase or decrease first number to target number.
52 : ''' </summary>
53 : ''' <param name="firstNumber">The first number.</param>
54 : ''' <param name="targetNumber">The target number.</param>
55 : ''' <returns>New value of first number</returns>
56 : Private Function StepCloser(ByVal firstNumber As Integer, ByVal targetNumber As Integer) As Integer
58 : If firstNumber < targetNumber Then
59 : firstNumber += StepSpeed
60 : If firstNumber > targetNumber Then firstNumber = targetNumber
62 : ElseIf firstNumber > targetNumber Then
63 : firstNumber -= StepSpeed
64 : If firstNumber < targetNumber Then firstNumber = targetNumber
66 : End If
68 : Return firstNumber
69 : End Function
72 : Private Delegate Sub DelegateChangeColor(ByVal Color As Color, ByVal progressBar As ToolStripProgressBar)
73 : ''' <summary>
74 : ''' Changes the progressbar color.
75 : ''' </summary>
76 : ''' <param name="color">The color.</param>
77 : ''' <param name="progressBar">The progress bar.</param>
78 : Private Sub ChangeColor(ByVal color As Color, ByVal progressBar As ToolStripProgressBar)
79 : If InvokeRequired Then
80 : Invoke(New DelegateChangeColor(AddressOf ChangeColor), color, progressBar)
82 : Else
83 : progressBar.ForeColor = color
84 : End If
85 : End Sub
87 : %>
Yorumlar
Aşağıdaki form aracılığı ile yorumlarınızı ve fikirlerinizi gönderebilirsiniz. Henüz bu konu hakkında bir yorum yazılmamış.
Yorum Ekle
Color Transition Effect in .NET Windows Forms (Progressbar or something else) ile İlişkili Olabilecek Yazılar - Haberler
PDF Dergi RöportajıArayı Açmayalım
Bilişim Rüzgarında Bilişim Suçları Röportajı
WPF - Windows Presentation Framework Nedir?
Network Security Assessment ve SQL Injection Cheatsheet
Diğer Yazılar
Comic Display, Çizgi Roman Okuma Zımbırtısı
Commandline (Komut) Uygulamalar ile Daha Rahat Çalışmak
Compex - 04-07 Aralık
Component olmadan Basit ASP Upload
Computer Arts, 3D Tasarım, Photoshop vs.
Cookbooks - Aren't they so good?
Cookie & IP Kontrollerini Geçmek
Core Force
Crysis - Cry Engine 2
Crysis Demo Download
CSRF, XSS, SQL Injection den Korunma ve Diger Korunma Geyikleri
CSS Aksiyonları...
CSS Atraksiyonları
CSS Hackimsi
CSS History Araklama Açığı
CSS Import ile XSS ve Türevleri
Ctrl + Shift + B
Cumartesi
Cumartesi 11:00 Bizim Radyo' dayım
Neredeyim ?
Ferruh.Mavituna » Kod Parçaları (Code Snippets) » Color Transition Effect in .NET Windows Forms (Progressbar or something else)