今天学习了刘金玉老师零基础VB教程的第41-42期,学习的主要内容如何使用滚动条和通过管理员来配置其他用户权限。
一、如何使用滚动条
1.滚动条分为横向滚动条(hscroll)和纵向滚动条(Vscroll)
2.滚动条min属性,滚动条的最小值;max属性,滚动条的最大值,value属性的内容表示滚动条的当前值。
3.hscroll和Vscroll控件的常用事件。
scroll事件:当我们鼠标点拉滚动条的时候触发。
Change事件:当滚动条的值发生变化的时候执行相应的指令。
4.案例:用滚动条控制字体大小和颜色深浅
Private Sub HScroll1_Change()
Label1.FontSize = HScroll1.Value
End Sub
Private Sub Label1_Click()
End Sub
Private Sub VScroll1_Change()
Label1.ForeColor = RGB(0, 0, VScroll1.Value)
End Sub
二、如何通过管理员来配置其他用户权限
案例:通过管理员配置非管理员用户可以查看哪些照片内容的权限
1.如图新建三个窗体,并在相应窗体新建相应的控件。
2.输入代码:
窗体一代码:
Private Sub Command1_Click()
If Trim) = "sichuan" Then
Form3.Show
Unload Form1
End If
If Trim) = "sichuan123" Then
Form2.Show
Form3.Show
Unload Form1
End If
End Sub
窗体二代码:
Private Sub Check1_Click(Index As Integer)
Open A & "; For Output As #1
Dim i%, s$, p$
s = "游客:"
For i = o To C Step 1
If Check1(i).Value = 1 Then
p = p & Check1(i).Caption & ","
End If
Next i
p = "," & p
Print #1, s & p
Close #1
End Sub
Private Sub Form_Load()
Dim m As String
Open A & "; For Input As #2
Do Until EOF(2)
Dim t$
Line Input #2, t
Dim s() As String
s = Split(t, ":")
If s(0) = "游客" Then
Dim i%
For i = 0 To C Step 1
Dim a$
a = "," & Check1(i).Caption & ","
If InStr(1, s(1), a, vbBinaryCompare) > 0 Then
m = m & CStr(i) & ","
End If
Next i
End If
Loop
Close #2
Dim z() As String
z = Split(m, ",")
Dim j%
For j = 0 To UBound(z) - 1 Step 1
Check1(j).Value = 1
Next j
End Sub
窗体三代码:
Private Sub Form_Load()
Open A & "; For Input As #3
Do Until EOF(3)
Dim t$
Line Input #3, t
Dim s() As String
s = Split(t, ":")
If s(0) = "游客" Then
If InStr(1, s(1), "第一张图片查看权限", vbbinarycopare) > 0 Then
Image1.Visible = True
Label1.Visible = True
End If
If InStr(1, s(1), "第二张图片查看权限", vbbinarycopare) > 0 Then
Image2.Visible = True
Label2.Visible = True
End If
Exit Do
End If
Loop
Close #3
End Sub
3.试运行: