实现一个会改变表单背景颜色的轨迹栏 [英] implementing a trackbar that will change background color of form
本文介绍了实现一个会改变表单背景颜色的轨迹栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的表单上有一个轨迹栏,它对应于背景颜色的色调,范围为 1 到 360,另一个轨迹栏对应于背景颜色的饱和度,在1 到 50 的范围.
i would like to have a trackbar on my form that will correspond to the HUE of the color of the backgruond, given a range of 1 to 360, and another trackbar that will correspond to saturation of the color of the backgruond, within a range of 1 to 50.
推荐答案
使用 HSVtoRGB
过程发现 此处,您可以将 TrackBar
控件挂钩到相同的事件处理程序并使用以下代码:
Using the HSVtoRGB
procedure found here, you can hook both your TrackBar
controls to the same event handler and use this code:
Private Sub tbHUE_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbHUE.Scroll, tbSaturation.Scroll
Dim r, g, b As Integer
HSVtoRGB(r, g, b, tbHUE.Value, tbSaturation.Value / 50, 255)
BackColor = Color.FromArgb(r, g, b)
End Sub
这是更正的程序,因为链接中的程序并没有真正遵循最佳实践:
Here is the corrected procedure since the one in the link doesn't really follow best practices:
Private Sub HSVtoRGB(ByRef Red As Integer, ByRef Green As Integer, ByRef Blue As Integer, ByVal Hue As Double, ByVal Sat As Double, ByVal Value As Integer)
Dim i As Integer
Dim f As Double, p As Double, q As Double, t As Double
If Sat = 0 Then
Red = Value
Green = Value
Blue = Value
Exit Sub
End If
i = CInt(Hue) \ 60
Hue = Hue / 60
f = Hue - i
p = Value * (1 - Sat)
q = Value * (1 - Sat * f)
t = Value * (1 - Sat * (1 - f))
Select Case i
Case 0
Red = Value
Green = CInt(t)
Blue = CInt(p)
Case 1
Red = CInt(q)
Green = Value
Blue = CInt(p)
Case 2
Red = CInt(p)
Green = Value
Blue = CInt(t)
Case 3
Red = CInt(p)
Green = CInt(q)
Blue = Value
Case 4
Red = CInt(t)
Green = CInt(p)
Blue = Value
Case 5
Red = Value
Green = CInt(p)
Blue = CInt(q)
End Select
End Sub
这篇关于实现一个会改变表单背景颜色的轨迹栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文