.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Change window form color

Posted By:Abhisek Panda       Posted Date: October 26, 2009    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  
 

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.

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend