Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to change a value over a set period of time

how to change a value over a set period of time

Scheduled Pinned Locked Moved C#
tutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kennyhibs
    wrote on last edited by
    #1

    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

    OriginalGriffO L 2 Replies Last reply
    0
    • K kennyhibs

      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

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • K kennyhibs

        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

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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.


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups