How to change back color of window form using Track Bars in C#?
How to change
back color of window form using Track Bars in C#?
Hello
Friends! In this article we will learn that how build or make 3 different Track
Bars in C# using window forms. These track bars will use to set the
background color of the form. These kind of applications will realy increase
your love for c#. So Open your Visual Studio and try to make app like this and
follow my article step by step.
Here is the
screenshot of that track bar app that I built with different tools available in
tool box for window forms:
So in the
above picture you can see different tools that I have used with final out put.
These tools can be drag and drop from toolbox as I mentioned previously.
Lets try to
code this application.
Source Code C#:
___________________________________________________________________________
using System;
using System.Drawing;
using System.Windows.Forms;
namespace TR_Track_Bar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void
trackBar1_Scroll(object sender, EventArgs e)
{
//store the
track bar1 current value to the label1 text
label1.Text =
trackBar1.Value.ToString();
//change the
background of form according to the current value of all 3 bars
BackColor = Color.FromArgb(hScrollBar1.Value,
hScrollBar2.Value, trackBar1.Value);
}
private void
hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
//store the
scroll bar1 current value to the label2 text
label2.Text =
hScrollBar1.Value.ToString();
//change the
background of form according to the current value of all 3 bars
BackColor = Color.FromArgb(hScrollBar1.Value,
hScrollBar2.Value, trackBar1.Value);
}
private void
hScrollBar2_Scroll(object sender, ScrollEventArgs e)
{
//store the scroll
bar2 current value to the label3
label3.Text =
hScrollBar2.Value.ToString();
//change the
background of form according to the current value of all 3 bars
BackColor = Color.FromArgb(hScrollBar1.Value,
hScrollBar2.Value, trackBar1.Value);
}
}
}
______________________________________________________________________________
In above
code one thing to remember that Argb stands for Alpha, red, green and blue will
take all 3 bars values as RGB values and change the background color of window
form according to these values.
Here is the
final output when you run you code.
Final
output:
Video
Tutorial:
So please
give your suggestion in comment and follow my blog to get interesting technical
knowledge.
Comments
Post a Comment