Skip to content

Commit 9675647

Browse files
committed
Now animation is work everytime while checked, and the speed it depends on math calculations for alpha color from 0 to 255 and vice versa, Fix #8, Fix #9
1 parent f499738 commit 9675647

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

MetroSet UI/Controls/MetroSetCheckBox.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public StyleManager StyleManager
117117
private Style _style;
118118
private StyleManager _styleManager;
119119
private bool _checked;
120-
private readonly Timer _timer;
120+
private readonly System.Timers.Timer _timer;
121121
private int _alpha;
122122

123123
#endregion Internal Vars
@@ -136,12 +136,13 @@ public MetroSetCheckBox()
136136
Cursor = Cursors.Hand;
137137
BackColor = Color.Transparent;
138138
_utl = new Utilites();
139-
_timer = new Timer()
139+
_timer = new System.Timers.Timer()
140140
{
141141
Interval = 10,
142-
Enabled = false
142+
AutoReset = true,
143+
Enabled = true
143144
};
144-
_timer.Tick += SetCheckedChanged;
145+
_timer.Elapsed += SetCheckedChanged;
145146
ApplyTheme();
146147
}
147148

@@ -369,7 +370,6 @@ public bool Checked
369370
_checked = value;
370371
CheckedChanged?.Invoke(this);
371372
SetCheckedChanged(this, null);
372-
_timer.Enabled = value;
373373
CheckState = value ? Enums.CheckState.Checked : Enums.CheckState.Unchecked;
374374
Invalidate();
375375
}

MetroSet UI/Controls/MetroSetRadioButton.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public StyleManager StyleManager
116116
private Style _style;
117117
private StyleManager _styleManager;
118118
private bool _checked;
119-
private readonly Timer _timer;
119+
private readonly System.Timers.Timer _timer;
120120
private int _alpha;
121121

122122
#endregion Internal Vars
@@ -135,12 +135,13 @@ public MetroSetRadioButton()
135135
_utl = new Utilites();
136136
_alpha = 0;
137137
Cursor = Cursors.Hand;
138-
_timer = new Timer()
138+
_timer = new System.Timers.Timer()
139139
{
140140
Interval = 10,
141-
Enabled = false
141+
AutoReset = true,
142+
Enabled = true
142143
};
143-
_timer.Tick += SetCheckedChanged;
144+
_timer.Elapsed += SetCheckedChanged;
144145
ApplyTheme();
145146
}
146147

@@ -369,17 +370,8 @@ public bool Checked
369370
_checked = value;
370371
CheckedChanged?.Invoke(this);
371372
SetCheckedChanged(this, null);
372-
_timer.Enabled = value;
373373
UpdateState();
374-
switch (value)
375-
{
376-
case true:
377-
CheckState = Enums.CheckState.Checked;
378-
break;
379-
case false:
380-
CheckState = Enums.CheckState.Unchecked;
381-
break;
382-
}
374+
CheckState = value ? Enums.CheckState.Checked : Enums.CheckState.Unchecked;
383375
Invalidate();
384376
}
385377
}

0 commit comments

Comments
 (0)