VB6 ColorBar program using RGBby Solitaire (Login Solitaire1)S Years ago I wrote a simple VB6 ColorBar program with sliders that you can use for each of the R, G, or B values. It displays over 16 million colors. The picture box instantly changes to show the resulting color. Labels also display the changing values for R, G, and B, as well as the changing Hexadecimal value. Start a new VB6 project and place the following controls on the form: 4 labels named: lblRed, lblGreen, lblBlue, and lblHex 3 vertical scroll bars named: vsbRed, vsbGreen, and vsbBlue 1 picture box named: picColor 2 command buttons named: cmdClear, and cmdExit Place each scroll bar below the matching label. Place the Hex label to the right of the color labels. Place the picture box below the Hex label. Place the buttons below the picture box. Change the Max value of each scroll bar to 255, Min to 0, LargeChange to 10, SmallChange to 1. Labels' Autsize should be False. Captions should be: Red 0, Green 0, Blue 0, and Hexadecimal &&H000000&& Change the size of each label so it displays the color name (or word) on top and the number just under it. When the program runs, it will just change the number. Here is the code: ------------------------------------------------------------------------ Option Explicit Dim mRedval As Integer, mGreenval As Integer, mBlueval As Integer 'Change event works by clicking on gray area or arrows. 'Change Event occurs as soon as mouse button is released. 'Scroll event occurs when user drags the thumb. Private Sub vsbRed_Change() mRedval = vsbRed.Value lblRed.Caption = "Red" & vbCrLf & mRedval picColor.BackColor = RGB(mRedval, mGreenval, mBlueval) Call hexcode End Sub Private Sub vsbRed_Scroll() mRedval = vsbRed.Value lblRed.Caption = "Red" & vbCrLf & mRedval picColor.BackColor = RGB(mRedval, mGreenval, mBlueval) Call hexcode End Sub Private Sub vsbGreen_Change() mGreenval = vsbGreen.Value lblGreen.Caption = "Green" & vbCrLf & mGreenval picColor.BackColor = RGB(mRedval, mGreenval, mBlueval) Call hexcode End Sub Private Sub vsbGreen_Scroll() mGreenval = vsbGreen.Value lblGreen.Caption = "Green" & vbCrLf & mGreenval picColor.BackColor = RGB(mRedval, mGreenval, mBlueval) Call hexcode End Sub Private Sub vsbBlue_Change() mBlueval = vsbBlue.Value lblBlue.Caption = "Blue" & vbCrLf & mBlueval picColor.BackColor = RGB(mRedval, mGreenval, mBlueval) Call hexcode End Sub Private Sub vsbBlue_Scroll() mBlueval = vsbBlue.Value lblBlue.Caption = "Blue" & vbCrLf & mBlueval picColor.BackColor = RGB(mRedval, mGreenval, mBlueval) Call hexcode End Sub Private Sub cmdClear_Click() vsbRed.Value = 0 vsbGreen.Value = 0 vsbBlue.Value = 0 vsbRed.SetFocus End Sub Sub hexcode() Dim hexblue As String, hexgreen As String, hexred As String Dim hexnum As String hexblue = Hex(mBlueval) hexgreen = Hex(mGreenval) hexred = Hex(mRedval) If mBlueval < 16 Then hexblue = "0" & hexblue If mGreenval < 16 Then hexgreen = "0" & hexgreen If mRedval < 16 Then hexred = "0" & hexred hexnum = hexblue & hexgreen & hexred lblHex.Caption = "Hexadecimal" & vbCrLf & "&&H" & hexnum & "&&" End Sub Private Sub cmdExit_Click() End End Sub
|