Click here to Skip to main content
Licence CPOL
First Posted 19 May 2010
Views 11,809
Downloads 381
Bookmarked 25 times

TimeBarControl

By | 30 May 2010 | Article
Control to display the time progress line
TimeBar.jpg

Introduction

In advance, I shall make a reservation that my English is very bad. Sorry!

Control capabilities:

  • Dragging the cursor on a scale
  • Two modes of nice background
  • Custom colors for mixed background

Background

Events:

  • Tick() - Occurs every time when event Tick() occurs by Internal Timer object
  • TimeHasExpired - Occurs when time has expired
  • UserBeginChangeTime - When user captures the cursor on TimeBar
  • UserEndChangeTime - Occurs when MouseUp occurs

While cursor is captured by the mouse - for each movement of the mouse, there is event Tick() and internal time is changed. In property 'Now' is the current time.

Using the Code

For using this TimeBar, just add it to your project, change settings as you like and setup event handlers.

When method TimeBar.Start() is caused, method Timer.Start() through the set interval causes event handler Timer_Tick (object sender, EventArgs e). In it, the handler causes the Advance() method.

public void Start()
{
    timer.Start();
    if(!backgroundWorker.IsBusy)
    {
        backgroundWorker.RunWorkerAsync();
        now = 0;
        cursor_location.X = line_left;
        if(Tick != null)
            Tick(this, null);// this is for subscribers
    }
}

private void timer_Tick(object sender, EventArgs e)
{
    this.Advance();
}

/// <summary>
/// To advance the cursor on value of an interval
/// </summary>
public void Advance()
{
    //move cursor
    cursor_location.X += pixToSec / (1000/timer.Interval);
    //change time
    now += (float)1 / (1000/timer.Interval);
    if (now >= duration)            
    {
        Stop();
    }
    //notify subscribers
    else if (Tick != null) Tick(this, null);
}        

At this time, backgroundWorker1 runs background to roll:

    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;
        while (!worker.CancellationPending)
        {
            Application.DoEvents();
            System.Threading.Thread.Sleep((int)lightSpeed);
            worker.ReportProgress(0);
        }
    }
    
    float pix = 0;
    private void backgroundWorker_ProgressChanged
	(object sender, System.ComponentModel.ProgressChangedEventArgs e)
    {
        //this event treats in Form thread. 
        //And changes in this handler is thread-self.
       
        //for LightStyle.Light            
        focus += 0.01f;
        if (focus > 1.0f)
        {
            focus = 0f;
            //Delay between cycles
            System.Threading.Thread.Sleep(100);
        }
        
        //for LightStyle.Fill
        pix++;            
        if (pix % this.Width == 0)
            pix = 0;
            
        //Parabola function for increasing to center
        scale = (focus - 0.5f) * (focus - 0.5f);
        scale *= 4;
        scale = 1 - scale;
        
        this.BackgroundImage.Dispose();
        this.BackgroundImage = MakeBackground(focus, scale);
        
        this.Refresh();
    }

I think that my control requires editing and optimization. I will come back to this work later. I await your comments!

History

  • 19.05.2010 - version 1.0.0.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Evgeniy Stepanow

Software Developer
Diacom Corporate & Asket Ink.
Russian Federation Russian Federation

Member

I was born in the Murmansk city of the Russian Federation in 1984. In 2001 had experience of programming on ZX Speccy assembler. It is interesting, whether many know this platform))?
2002 - 2007: programmed on С++
2007 - 2010: .Net C#
I write programs for the medical purposes.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThanks for sharing (: Pinmembergutierrezgileta18:31 1 Jun '10  
GeneralShort note PinmemberPetrykin Victor1:48 30 May '10  
GeneralRe: Short note PinmemberEvgeniy Stepanow4:17 30 May '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 30 May 2010
Article Copyright 2010 by Evgeniy Stepanow
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid