Below is the project which contains 3 horizontal scrollbars if we slides the scrollbars the background color of the form is changing accordingly. first scrollbar is adding red color, second adding green and third one adding blue upon scrolling or sliding. Take 3 horizontal scrollbars and assign them maximum value of 255(from 0) to each one.
Below is the designer view of the project:
Below is the source code of the project:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Color_RGB_demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void RGBdemo()
{
int r = hScrollBar1.Value;
int g = hScrollBar2.Value;
int b = hScrollBar3.Value;
Color c1 = Color.FromArgb(r, g, b);
this.BackColor = c1;
}
private void hScrollBar2_Scroll(object sender, ScrollEventArgs e)
{
RGBdemo();
}
private void hScrollBar3_Scroll(object sender, ScrollEventArgs e)
{
RGBdemo();
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
RGBdemo();
}
}
}
Comments
Post a Comment