Change The Window Form Color

Abhisek
Posted by Abhisek under VB.NET category on | Views : 2806
It is a window application. First create a window application in VB.NET and place three labels and horizontal scroll bars on the form.

Change the text property of the labels to RED, GREEN and BLUE. Change the name property of the scroll-bars to hsbRed, hsbGreen, hsbBlue respectively. Also make the maximum property of all the scroll-bars to 255.

Now open the code editor and enter the following codes. Build the application and save it.



Public Class Form1

Private Sub hsbRed_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbRed.Scroll
Me.BackColor = ColorTranslator.FromOle(RGB(hsbRed.Value, hsbGreen.Value, hsbBlue.Value))
End Sub

Private Sub hsbGreen_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbGreen.Scroll
Me.BackColor = ColorTranslator.FromOle(RGB(hsbRed.Value, hsbGreen.Value, hsbBlue.Value))
End Sub

Private Sub hsbBlue_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbBlue.Scroll
Me.BackColor = ColorTranslator.FromOle(RGB(hsbRed.Value, hsbGreen.Value, hsbBlue.Value))
End Sub
End Class



DESCRIPTION


When you run the application the window will appear with three scroll-bars. When all the scroll-bars will be set to minimum the color will be black and when set to maximum the color will be white. Scroll the scroll-bars to different positions to get different colors.

This application uses RGB() method,.

Me.BackColor = ColorTranslator.FromOle(RGB(hsbRed.Value, hsbGreen.Value, hsbBlue.Value))

This line is responsible to change the form's color according to the scroll-bars value. The FromOle() is responsible for drawing graphics on the form.

Comments or Responses

Login to post response