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);
}
}
private void timer_Tick(object sender, EventArgs e)
{
this.Advance();
}
public void Advance()
{
cursor_location.X += pixToSec / (1000/timer.Interval);
now += (float)1 / (1000/timer.Interval);
if (now >= duration)
{
Stop();
}
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)
{
focus += 0.01f;
if (focus > 1.0f)
{
focus = 0f;
System.Threading.Thread.Sleep(100);
}
pix++;
if (pix % this.Width == 0)
pix = 0;
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
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.