how to change a value over a set period of time
-
Hi again trying to create a simple video fade effect by changing the contrast value of video from 0 to -128 over a period of 2 seconds, tried using time_tick and a for loop but it didnt work as all that happened was timer started and then loop exacuted timer set to 100 millisecs private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < -128; i--) { contast = i } } anyone point me in right direction thanks
-
Hi again trying to create a simple video fade effect by changing the contrast value of video from 0 to -128 over a period of 2 seconds, tried using time_tick and a for loop but it didnt work as all that happened was timer started and then loop exacuted timer set to 100 millisecs private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < -128; i--) { contast = i } } anyone point me in right direction thanks
Try this:
private int contrast = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (contrast > -128)
{
contrast--;
}
else
{
timer1.Stop();
}
}You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
Hi again trying to create a simple video fade effect by changing the contrast value of video from 0 to -128 over a period of 2 seconds, tried using time_tick and a for loop but it didnt work as all that happened was timer started and then loop exacuted timer set to 100 millisecs private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < -128; i--) { contast = i } } anyone point me in right direction thanks
Hi, having the loop execute completely within a single timer tick won't cut it; what you need is one tiny step on each of a number of timer ticks, as Griff already has shown. FYI: that requires a small time step, probably pretty close to what your system is willing to offer through a System.Windows.Forms.Timer; see my article Timer surprises, and how to avoid them[^] BTW: your for loop's exit condition was wrong too. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.