VB中能不能将文本框的输入数值限定为一个范围
- 提问者网友:温旧梦泪无声
- 2021-06-01 22:58
- 五星知识达人网友:末日狂欢
- 2021-06-02 00:17
比如,你要对Text1的输入进行限制。可以使用下面代码:
Private Sub Text1_Change()
If Val(Trim(Text1.Text)) < 0 Or Val(Trim(Text1.Text)) > 255 Then
Text1.Text = ""
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
'禁止输入非数字字符
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
- 1楼网友:雾月
- 2021-06-02 02:41
Private Sub Text1_Change() Text1 = Int(Val(Text1)) If Text1 > 255 Then Text1 = 255 End Sub
- 2楼网友:一袍清酒付
- 2021-06-02 01:19
不知道这个行不行,你先试一试
dim rgbvalue as integer
dim rgbvalueback as integer
dim r as integer
dim g as integer
dim b as integer
r = hscrollbar1.value
g = hscrollbar2.value
b = hscrollbar3.value
textbox1.text = r
textbox2.text = g
textbox3.text = b
rgbvalue = rgb(r, g, b)
rgbvalueback = rgb(255 - r, 255 - g, 255 - b)
me.backcolor = system.drawing.colortranslator.fromole(rgbvalue)
label1.backcolor = system.drawing.colortranslator.fromole(rgbvalue)
label2.backcolor = system.drawing.colortranslator.fromole(rgbvalue)
label3.backcolor = system.drawing.colortranslator.fromole(rgbvalue)
label1.forecolor = system.drawing.colortranslator.fromole(rgbvalueback)
label2.forecolor = system.drawing.colortranslator.fromole(rgbvalueback)
label3.forecolor = system.drawing.colortranslator.fromole(rgbvalueback)
- 3楼网友:十鸦
- 2021-06-02 00:44