home *** CD-ROM | disk | FTP | other *** search
- Type ScrollBarMasterForm From SampleMasterForm
- Dim Label1 As New Label
- Dim lblSizeBox As New Label
- Dim sbrHorizontal As New ScrollBar
- Dim sbrVertical As New ScrollBar
- Dim Label2 As New Label
- Dim sbrRed As New ScrollBar
- Dim sbrGreen As New ScrollBar
- Dim sbrBlue As New ScrollBar
- Dim Label3 As New Label
- Dim Label4 As New Label
- Dim Label5 As New Label
- Dim ctrlColor As New Control
- Dim lblRed As New Label
- Dim lblGreen As New Label
- Dim lblBlue As New Label
- Dim Label6 As New Label
- Dim lblColorValue As New Label
- Dim Label8 As New Label
- Dim Label9 As New Label
- Dim Label10 As New Label
- Dim sbrHue As New ScrollBar
- Dim sbrSaturation As New ScrollBar
- Dim sbrValue As New ScrollBar
- Dim lblHue As New Label
- Dim lblSaturation As New Label
- Dim lblValue As New Label
- Dim ChangeFlag As Integer
- Dim GotFocusFlag As Integer
- Dim RED As Integer
- Dim GREEN As Integer
- Dim BLUE As Integer
- Dim HUE As Integer
- Dim SATURATION As Integer
- Dim VALUE As Integer
- Dim LoopBack As Integer
- Dim Label7 As New Label
- Dim txtColorValue As New TextBox
- Dim Label11 As New Label
- Dim cmdConvert As New Button
- Dim Label12 As New Label
- Dim Label13 As New Label
- Dim lblGreenValue As New Label
- Dim lblRedValue As New Label
- Dim Label15 As New Label
- Dim lblBlueValue As New Label
-
- ' METHODS for object: ScrollBarMasterForm
- Sub sbrHorizontal_Change()
- lblSizeBox.Left = 2700 - ((sbrHorizontal.Value - 450) / 2)
- lblSizeBox.Width = sbrHorizontal.Value
- sbrHorizontal.Refresh
- End Sub
-
- Sub sbrVertical_Change()
- lblSizeBox.Top = 1050 - ((sbrVertical.Value - 450) / 2)
- lblSizeBox.Height = sbrVertical.Value
- sbrVertical.Refresh
- End Sub
-
- Sub sbrRed_GotFocus()
- GotFocusFlag = 1
- End Sub
-
- Sub sbrGreen_GotFocus()
- GotFocusFlag = 2
- End Sub
-
- Sub sbrBlue_GotFocus()
- GotFocusFlag = 3
- End Sub
-
- Sub sbrHue_GotFocus()
- GotFocusFlag = 4
- End Sub
-
- Sub sbrValue_GotFocus()
- GotFocusFlag = 6
- End Sub
-
- Sub sbrRed_Scroll()
- sbrRed_Change
- End Sub
-
- Sub sbrGreen_Scroll()
- sbrGreen_Change
- End Sub
-
- Sub sbrBlue_Scroll()
- sbrBlue_Change
- End Sub
-
- Sub sbrHue_Scroll()
- sbrHue_Change
- End Sub
-
- Sub sbrSaturation_Scroll()
- sbrSaturation_Change
- End Sub
-
- Sub sbrValue_Scroll()
- sbrValue_Change
- End Sub
-
- Sub sbrHue_Change()
- ChangeFlag = 4
- lblHue.Caption = sbrHue.Value
- UpdateColor
- sbrHue.Refresh
- End Sub
-
- Sub sbrSaturation_Change()
- ChangeFlag = 5
- lblSaturation.Caption = sbrSaturation.Value
- UpdateColor
- sbrSaturation.Refresh
- End Sub
-
- Sub sbrValue_Change()
- ChangeFlag = 6
- lblValue.Caption = sbrValue.Value
- UpdateColor
- sbrValue.Refresh
- End Sub
-
- Sub sbrRed_Change()
- ChangeFlag = 1
- lblRed.Caption = sbrRed.Value
- UpdateColor
- sbrRed.Refresh
- End Sub
-
- Sub sbrBlue_Change()
- ChangeFlag = 3
- lblBlue.Caption = sbrBlue.Value
- UpdateColor
- sbrBlue.Refresh
- End Sub
-
- Sub sbrSaturation_GotFocus()
- GotFocusFlag = 5
- End Sub
-
- Sub sbrGreen_Change()
- ChangeFlag = 2
- lblGreen.Caption = sbrGreen.Value
- UpdateColor
- sbrGreen.Refresh
- End Sub
-
- Sub UpdateColor()
- Dim rgb_value As Long
-
- ' If this routine is being called because of a scrollbar value being updated
- ' then bypass this routine
- If LoopBack == 1 Then Exit Sub
-
- ' Be sure scroll bars are coordinated
- If ChangeFlag > 0 And ChangeFlag == GotFocusFlag Then
- If ChangeFlag < 4 Then
- ' Get current RGB scroll bar values
- RED = sbrRed.Value
- GREEN = sbrGreen.Value
- BLUE = sbrBlue.Value
-
- ' Convert RGB to HSV
- RGB2HSV
-
- ' Set HSV scroll bars
- LoopBack = 1
- sbrHue.Value = HUE
- sbrSaturation.Value = SATURATION
- sbrValue.Value = VALUE
- LoopBack = 0
- Else
- ' Get current HSV scroll bar values
- HUE = sbrHue.Value
- SATURATION = sbrSaturation.Value
- VALUE = sbrValue.Value
-
- ' Convert HSV to RGB
- HSV2RGB
-
- ' Set RGB scrollbars
- LoopBack = 1
- sbrRed.Value = RED
- sbrGreen.Value = GREEN
- sbrBlue.Value = BLUE
- LoopBack = 0
- End If
- End If
-
- ' Get RGB scroll bar values
- RED = sbrRed.Value
- GREEN = sbrGreen.Value
- BLUE = sbrBlue.Value
-
- ' Convert R, G, and B values to long color value
- rgb_value = RGB(RED, GREEN, BLUE)
-
- ' Display color in picture box
- ctrlColor.BackColor = rgb_value
-
- ' Display long color value
- lblColorValue.Caption = "H" & Hex(rgb_value)
-
-
- ' ctrlColor.BackColor = RGB(sbrRed.Value, sbrGreen.Value, sbrBlue.Value)
- ' Update the value labels for each color
- ' lblRedValue.Caption = sbrRed.Value
- ' lblGreenValue.Caption = sbrGreen.Value
- ' lblBlueValue.Caption = sbrBlue.Value
- End Sub
-
- Sub HSV2RGB()
- Dim red As Single
- Dim green As Single
- Dim blue As Single
- Dim saturation As Single
- Dim value As Single
- Dim hue_value As Single
- Dim i As Integer
- Dim f, p, q, t As Single
-
- saturation = SATURATION / 100.0
- value = VALUE / 100.0
- If SATURATION == 0 Then
- red = value
- green = value
- blue = value
- Else
- hue_value = HUE / 60.0
- If hue_value == 6 Then hue_value = 0
- i = int(hue_value)
- f = hue_value - i
- p = value * (1 - saturation)
- q = value * (1 - (saturation * f))
- t = value * (1 - (saturation * (1 - f)))
- Select Case i
- Case 0
- red = value
- green = t
- blue = p
- Case 1
- red = q
- green = value
- blue = p
- Case 2
- red = p
- green = value
- blue = t
- Case 3
- red = p
- green = q
- blue = value
- Case 4
- red = t
- green = p
- blue = value
- Case 5
- red = value
- green = p
- blue = q
- End Select
- End If
-
- RED = int(255.9999 * red)
- GREEN = int(255.9999 * green)
- BLUE = int(255.9999 * blue)
-
- End Sub
-
- Sub RGB2HSV ()
- Dim value_red As Single
- Dim value_green As Single
- Dim value_blue As Single
- Dim max As Single
- Dim min As Single
- Dim red_color As Single
- Dim green_color As Single
- Dim blue_color As Single
- Dim value_value As Single
- Dim saturation_value As Single
- Dim hue_value As Single
-
- value_red = RED / 255.0
- value_green = GREEN / 255.0
- value_blue = BLUE / 255.0
-
- max = value_red
- If value_green > max Then max = value_green
- If value_blue > max Then max = value_blue
-
- min = value_red
- If value_green < min Then min = value_green
- If value_blue < min Then min = value_blue
-
- value_value = max
- If max <> 0 Then
- saturation_value = (max - min) / max
- Else
- saturation_value = 0
- End If
- If saturation_value == 0 Then
- HUE = 0
- Else
- red_color = (max - value_red) / (max - min)
- green_color = (max - value_green) / (max - min)
- blue_color = (max - value_blue) / (max - min)
- Select Case max
- Case value_red
- hue_value = blue_color - green_color
- Case value_green
- hue_value = 2 + red_color - blue_color
- Case value_blue
- hue_value = 4 + green_color - red_color
- End Select
- hue_value = hue_value * 60
- If hue_value < 0 Then
- HUE = hue_value + 360
- Else
- HUE = hue_value
- End If
- End If
-
- SATURATION = saturation_value * 100
- VALUE = value_value * 100
-
- End Sub
-
- Sub ResetApplication_Click ()
-
- ' Initialize the ScrollBar start positions
- sbrHorizontal.Value = 450
- sbrVertical.Value = 450
-
- ' Initialize ScrollBar size box
- lblSizeBox.Left = 2700
- lblSizeBox.Top = 1050
- lblSizeBox.Height = 450
- lblSizeBox.Width = 450
-
- ' Initialize the ScrollBar ranges
- sbrHorizontal.Min = 450
- sbrHorizontal.Max = 4650
- sbrVertical.Min = 450
- sbrVertical.Max = 1050
-
- ' Initialize the ScrollBar increments
- sbrHorizontal.SmallChange = 100
- sbrHorizontal.LargeChange = 1000
- sbrVertical.SmallChange = 100
- sbrVertical.LargeChange = 1000
-
- ' Initialize the color of the Color control
- ctrlColor.BackColor = RGB(0, 0, 0)
-
- ' Initialize the Red, Green, Blue ScrollBars
- sbrRed.Value = 0
- sbrGreen.Value = 0
- sbrBlue.Value = 0
- sbrRed.Min = 0
- sbrRed.Max = 255
- sbrRed.SmallChange = 1
- sbrRed.LargeChange = 20
- sbrGreen.Min = 0
- sbrGreen.Max = 255
- sbrGreen.SmallChange = 1
- sbrGreen.LargeChange = 20
- sbrBlue.Min = 0
- sbrBlue.Max = 255
- sbrBlue.SmallChange = 1
- sbrBlue.LargeChange = 20
-
- ' Initialize the Hue, Saturation, Value ScrollBars
- sbrHue.Value = 0
- sbrSaturation.Value = 0
- sbrValue.Value = 0
- sbrHue.Min = 0
- sbrHue.Max = 360
- sbrHue.SmallChange = 1
- sbrHue.LargeChange = 20
- sbrSaturation.Min = 0
- sbrSaturation.Max = 100
- sbrSaturation.SmallChange = 1
- sbrSaturation.LargeChange = 20
- sbrValue.Min = 0
- sbrValue.Max = 100
- sbrValue.SmallChange = 1
- sbrValue.LargeChange = 20
-
- ' Initialize the flags, the flags are used to know when a particular scrollbar is
- ' being clicked or scrolled vrs. ones that are being automatically updated.
- ChangeFlag = 1
- GotFocusFlag = 1
- ' flag to prevent loopback calls to UpdateColor routine
- LoopBack = 0
-
- ' Initialize the color conversion
- txtColorValue.Text = ""
- lblRedValue.Caption = ""
- lblGreenValue.Caption = ""
- lblBlueValue.Caption = ""
-
- End Sub
-
- Sub cmdConvert_Click()
- Static colorval As Long
- Dim R, G, B As Integer
-
- If txtColorValue.Text == "" Then
- InfoBox.Message("", "No color value has been entered.")
- Exit Sub
- End If
-
- ' colorval = Val(txtColorValue.Text)
- colorval = Val(LTrim(txtColorValue.Text) & "&")
-
- lblRedValue.Caption = (colorval And &Hff)
- lblGreenValue.Caption = (colorval And &Hff00) \ 256
- lblBlueValue.Caption = (colorval And &Hff0000) \ 65536
-
- End Sub
-
- End Type
-
- Begin Code
- ' Reconstruction commands for object: ScrollBarMasterForm
- '
- With ScrollBarMasterForm
- With .Label1
- .Caption = "1. Click Horizontal and Vertical ScrollBars to change size."
- .ForeColor = 13107200
- .Move(300, 300, 5700, 300)
- End With 'ScrollBarMasterForm.Label1
- With .lblSizeBox
- .BackColor = 16777215
- .Move(2700, 1050, 450, 450)
- .BorderStyle = "Fixed Single"
- End With 'ScrollBarMasterForm.lblSizeBox
- With .sbrHorizontal
- .Move(600, 1950, 4650, 300)
- .Min = 450
- .Max = 4650
- .Value = 450
- .Orientation = "Horizontal"
- .Move(600, 1950, 4650, 300)
- End With 'ScrollBarMasterForm.sbrHorizontal
- With .sbrVertical
- .Move(5700, 750, 300, 1050)
- .Min = 450
- .Max = 1050
- .Value = 450
- End With 'ScrollBarMasterForm.sbrVertical
- With .Label2
- .Caption = "2. Click Red, Green and Blue ScrollBars to change color."
- .ForeColor = 13107200
- .Move(300, 2550, 5700, 300)
- End With 'ScrollBarMasterForm.Label2
- With .sbrRed
- .Move(1500, 3000, 2100, 300)
- .SmallChange = 1
- .LargeChange = 20
- .Max = 255
- .Orientation = "Horizontal"
- .Move(1500, 3000, 2100, 300)
- End With 'ScrollBarMasterForm.sbrRed
- With .sbrGreen
- .Move(1500, 3450, 2100, 300)
- .SmallChange = 1
- .LargeChange = 20
- .Max = 255
- .Orientation = "Horizontal"
- .Move(1500, 3450, 2100, 300)
- End With 'ScrollBarMasterForm.sbrGreen
- With .sbrBlue
- .Move(1500, 3900, 2100, 300)
- .SmallChange = 1
- .LargeChange = 20
- .Max = 255
- .Orientation = "Horizontal"
- .Move(1500, 3900, 2100, 300)
- End With 'ScrollBarMasterForm.sbrBlue
- With .Label3
- .Caption = "Red:"
- .ForeColor = 200
- .Move(450, 3000, 735, 300)
- .Alignment = "Right"
- End With 'ScrollBarMasterForm.Label3
- With .Label4
- .Caption = "Green:"
- .ForeColor = 34560
- .Move(450, 3450, 735, 300)
- .Alignment = "Right"
- End With 'ScrollBarMasterForm.Label4
- With .Label5
- .Caption = "Blue:"
- .ForeColor = 9830400
- .Move(450, 3900, 735, 300)
- .Alignment = "Right"
- End With 'ScrollBarMasterForm.Label5
- With .ctrlColor
- .BackColor = 0
- .Move(4650, 3000, 1350, 1800)
- End With 'ScrollBarMasterForm.ctrlColor
- With .lblRed
- .Caption = "0"
- .Move(3900, 3000, 435, 300)
- End With 'ScrollBarMasterForm.lblRed
- With .lblGreen
- .Caption = "0"
- .Move(3900, 3450, 435, 300)
- End With 'ScrollBarMasterForm.lblGreen
- With .lblBlue
- .Caption = "0"
- .Move(3900, 3900, 435, 300)
- End With 'ScrollBarMasterForm.lblBlue
- With .Label6
- .Caption = "Color Hex No:"
- .Move(4650, 4950, 1350, 300)
- End With 'ScrollBarMasterForm.Label6
- With .lblColorValue
- .Caption = "H0"
- .BackColor = 16777215
- .Move(4650, 5250, 1350, 300)
- .BorderStyle = "Fixed Single"
- .Alignment = "Center"
- End With 'ScrollBarMasterForm.lblColorValue
- With .Label8
- .Caption = "Hue:"
- .Move(300, 4350, 900, 300)
- .Alignment = "Right"
- End With 'ScrollBarMasterForm.Label8
- With .Label9
- .Caption = "Saturation:"
- .Move(150, 4800, 1050, 300)
- .Alignment = "Right"
- End With 'ScrollBarMasterForm.Label9
- With .Label10
- .Caption = "Value:"
- .Move(300, 5250, 900, 300)
- .Alignment = "Right"
- End With 'ScrollBarMasterForm.Label10
- With .sbrHue
- .Caption = "sbrHue"
- .Move(1500, 4350, 2100, 300)
- .SmallChange = 1
- .LargeChange = 20
- .Max = 360
- .Orientation = "Horizontal"
- .Move(1500, 4350, 2100, 300)
- End With 'ScrollBarMasterForm.sbrHue
- With .sbrSaturation
- .Caption = "sbrSaturation"
- .Move(1500, 4800, 2100, 300)
- .SmallChange = 1
- .LargeChange = 20
- .Max = 100
- .Orientation = "Horizontal"
- .Move(1500, 4800, 2100, 300)
- End With 'ScrollBarMasterForm.sbrSaturation
- With .sbrValue
- .Caption = "sbrValue"
- .Move(1500, 5250, 2100, 300)
- .SmallChange = 1
- .LargeChange = 20
- .Max = 100
- .Orientation = "Horizontal"
- .Move(1500, 5250, 2100, 300)
- End With 'ScrollBarMasterForm.sbrValue
- With .lblHue
- .Caption = "0"
- .Move(3900, 4350, 435, 300)
- End With 'ScrollBarMasterForm.lblHue
- With .lblSaturation
- .Caption = "0"
- .Move(3900, 4800, 435, 300)
- End With 'ScrollBarMasterForm.lblSaturation
- With .lblValue
- .Caption = "0"
- .Move(3900, 5250, 435, 300)
- End With 'ScrollBarMasterForm.lblValue
- With .Label7
- .Caption = "3. Enter a Color Value in the box and click Convert button."
- .ForeColor = 13107200
- .Move(300, 5850, 5700, 300)
- End With 'ScrollBarMasterForm.Label7
- With .txtColorValue
- .Move(2250, 6300, 1350, 330)
- End With 'ScrollBarMasterForm.txtColorValue
- With .Label11
- .Caption = "Decimal Value:"
- .Move(600, 6300, 1500, 300)
- End With 'ScrollBarMasterForm.Label11
- With .cmdConvert
- .Caption = "Convert"
- .Move(4800, 7050, 1200, 450)
- End With 'ScrollBarMasterForm.cmdConvert
- With .Label12
- .Caption = "RED"
- .ForeColor = 255
- .Move(600, 6900, 600, 300)
- End With 'ScrollBarMasterForm.Label12
- With .Label13
- .Caption = "GREEN"
- .ForeColor = 38400
- .Move(1650, 6900, 900, 300)
- End With 'ScrollBarMasterForm.Label13
- With .lblGreenValue
- .BackColor = 16777215
- .Move(1650, 7200, 750, 300)
- .BorderStyle = "Fixed Single"
- End With 'ScrollBarMasterForm.lblGreenValue
- With .lblRedValue
- .BackColor = 16777215
- .Move(600, 7200, 750, 300)
- .BorderStyle = "Fixed Single"
- End With 'ScrollBarMasterForm.lblRedValue
- With .Label15
- .Caption = "BLUE"
- .ForeColor = 9830400
- .Move(2850, 6900, 750, 300)
- End With 'ScrollBarMasterForm.Label15
- With .lblBlueValue
- .BackColor = 16777215
- .Move(2850, 7200, 750, 300)
- .BorderStyle = "Fixed Single"
- End With 'ScrollBarMasterForm.lblBlueValue
- With .helpfile
- .FileName = "W:\Examples\scrolbar\scrolbar.hlp"
- End With 'ScrollBarMasterForm.helpfile
- .Caption = "ScrollBar Demonstration"
- .Move(4080, 1815, 6420, 8490)
- .ChangeFlag = 1
- .GotFocusFlag = 1
- .RED = 0
- .GREEN = 0
- .BLUE = 0
- .HUE = 0
- .SATURATION = 0
- .VALUE = 0
- .LoopBack = 0
- .SampleDir = "W:\Examples\scrolbar\"
- .SampleName = "scrolbar"
- End With 'ScrollBarMasterForm
- End Code
-