vb编程,自定义变量实现颜色?请指教下
答案:3 悬赏:80 手机版
解决时间 2021-02-09 15:37
- 提问者网友:放下
- 2021-02-09 07:29
vb编程,自定义变量实现颜色?请指教下
最佳答案
- 五星知识达人网友:想偏头吻你
- 2021-02-09 08:46
其实这个问题特简单,但是三色需要三个文本框(数组控件)分别输入,设置红色、绿色、蓝色,在文本框的Text1_Change事件中设置Text2的颜色就可以了。
Private Sub Form_Load()
Text2.Text = "你好吗?"
Text2.FontSize = 20
Text2.FontBold = True
End Sub
Private Sub Text1_Change(Index As Integer)
Dim AA As Integer, BB As String
AA = Index
If AA = 0 Then BB = "红色"
If AA = 1 Then BB = "绿色"
If AA = 2 Then BB = "蓝色"
If IsNumeric(Text1(AA).Text) = False Then
MsgBox "你输入的" & BB & "不是数字,各种颜色的值必须是0-255之间的正整数!"
Text1(AA).Text = ""
Text1(AA).SetFocus
Exit Sub
End If
If Val(Text1(AA).Text) < 0 Or Val(Text1(AA).Text) > 255 Then
MsgBox "你输入的" & BB & "数字不正确,不能小于0,也不能大于255!"
Text1(AA).Text = ""
Text1(AA).SetFocus
Exit Sub
End If
If Val(Text1(0).Text) >= 0 And Val(Text1(0).Text) <= 255 And Val(Text1(1).Text) >= 0 And Val(Text1(1).Text) <= 255 And Val(Text1(2).Text) >= 0 And Val(Text1(2).Text) <= 255 Then
Text2.ForeColor = RGB(Val(Text1(0).Text), Val(Text1(1).Text), Val(Text1(2).Text))
End If
End Sub
Private Sub Form_Load()
Text2.Text = "你好吗?"
Text2.FontSize = 20
Text2.FontBold = True
End Sub
Private Sub Text1_Change(Index As Integer)
Dim AA As Integer, BB As String
AA = Index
If AA = 0 Then BB = "红色"
If AA = 1 Then BB = "绿色"
If AA = 2 Then BB = "蓝色"
If IsNumeric(Text1(AA).Text) = False Then
MsgBox "你输入的" & BB & "不是数字,各种颜色的值必须是0-255之间的正整数!"
Text1(AA).Text = ""
Text1(AA).SetFocus
Exit Sub
End If
If Val(Text1(AA).Text) < 0 Or Val(Text1(AA).Text) > 255 Then
MsgBox "你输入的" & BB & "数字不正确,不能小于0,也不能大于255!"
Text1(AA).Text = ""
Text1(AA).SetFocus
Exit Sub
End If
If Val(Text1(0).Text) >= 0 And Val(Text1(0).Text) <= 255 And Val(Text1(1).Text) >= 0 And Val(Text1(1).Text) <= 255 And Val(Text1(2).Text) >= 0 And Val(Text1(2).Text) <= 255 Then
Text2.ForeColor = RGB(Val(Text1(0).Text), Val(Text1(1).Text), Val(Text1(2).Text))
End If
End Sub
全部回答
- 1楼网友:行路难
- 2021-02-09 09:36
你这个可以通过 text1.backcolor=RGB 来调控颜色
- 2楼网友:山君与见山
- 2021-02-09 09:29
直接调用RGB函数就行了,使用文本框输入红绿蓝的值即可。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯