TrackBar

Similar to numericupdown, but it offers visualization for the value selection.

Track Bar
API: System.Windows.Forms.TrackBar
Naming Convension: trkxxxxxx
Properties of TrackBar
Property Description
Value Gets or sets the current value in the control.
Minimum Specifies the minimum value in the range.
Maximum Specifies the maximum value in the range.
TickFrequency Specifies the difference between each tick.
Orientation Horizontal / Vertical
TickStyle None, TopLeft, BottomRight, Both
Name, BackColor, ForeColor, Enabled, Visible, Size, Location, ContextMenuStrip, BorderStyle

Events of TrackBar
Property Description
Scroll, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave


Track Bar
Demo on TrackBar
Design
lblFontSize
trkFontSize
Minimum: 1
Maximum: 200
TickFrequency: 5
lblMyText
Text: 10

private void trkFontSize_Scroll(object sender, EventArgs e)
{
int n = trkFontSize.Value;
lblMyText.Font = new Font("Tahoma", n);
}

Timer

It is known as “Invisible Control”. That means it can’t be displayed on the form UI. But it works during the execution time. It performs background processing. It executes a certain logic, whenever a certain interval time is completed.
Track Bar
API: System.Windows.Forms.Timer
Naming Convension: tmrxxxxxx
Properties of Timer
Property Description
Interval Specifies the interval time of the timer, in the form of mille seconds.
Name, Enabled

Events of Timer
Event Description
Tick Executes on every completion of interval time.
Name, Enabled


Track Bar
Demo on Timer

Design
tmrTime
Interval: 1000
Enabled: true
lblTime

private void Form1_Load(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToLongTimeString();
}

private void tmrTime_Tick(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToLongTimeString();
}

Demo on Timer


Track Bar
Design
tmrBackColor
Interval: 500
Enabled: true


int n = 0;

private void tmrBackColor_Tick(object sender, EventArgs e)
{
n++;
switch (n)
{
case 1: this.BackColor = Color.Black; break;
case 2: this.BackColor = Color.Blue; break;
case 3: this.BackColor = Color.LightCoral; break;
case 4: this.BackColor = Color.LightCyan; break;
case 5: this.BackColor = Color.Green; break;
case 6: this.BackColor = Color.Red; break;
case 7: this.BackColor = Color.Chocolate; break;
case 8: this.BackColor = Color.DarkKhaki; break;
case 9: this.BackColor = Color.Firebrick; break;
case 10: this.BackColor = Color.Gold; break;
default: n = 0; break;
}
}

ProgressBar

It shows the progress of a certain process. It’s value is limited to the range of 0 to 100. Whenever its value is reached to 100, that means the process is completed. It can be implemented with the combination of timer control.
ProgressBar

API: System.Windows.Forms.ProgressBar
Naming Convension: prgxxxxxx
Properties of ProgressBar

Property Description
Value Gets or sets the current value in the control.
Minimum Specifies the minimum value in the range.
Maximum Specifies the maximum value in the range.
Name, BackColor, ForeColor, Enabled, Visible, Size, Location, ContextMenuStrip, BackgroundImage, BackgroundImageLayout

Events of ProgressBar
Event Description
Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave

Demo on Progress Bar

ProgressBar
Design
lblFileName
txtFileName
btnOpen
lblLoading
Visible: false
prgFile
Visible: false
txtContent
Multiline: true
Scrollbars: Both
WordWrap: false
Readonly: true
tmrFileOpen
Enabled: false
Interval: 100


using System.IO;
private void OpenFile()
{
string filename = txtFileName.Text;
FileInfo fobj = new FileInfo(filename);
if (fobj.Exists)
{
StreamReader sr = new StreamReader(filename);
string content = sr.ReadToEnd();
txtContent.Text = content;
sr.Close();
}
else
MessageBox.Show("File not found.");
}
private void btnOpen_Click(object sender, EventArgs e)
{
prgFile.Value = 0;
tmrFileOpen.Enabled = true;
lblLoading.Visible = true;
prgFile.Visible = true;
}
private void tmrFileOpen_Tick(object sender, EventArgs e)
{
prgFile.Value++;
if (prgFile.Value == 100)
{
tmrFileOpen.Enabled = false;
lblLoading.Visible = false;
prgFile.Visible = false;
OpenFile();
}
}