如何解决有没有办法根据 TrackBar 中的值范围指示 if-then 语句? (VB.NET)
我想在我的 Visual Studio 项目中使用 TrackBar。我的目标是让用户滚动 TrackBar 的指示器,并根据它所在的值范围,它会更改标签的文本。
以下是我如何尝试实现此目标的示例:
Private Sub ScrollBarProgress() Handles MyBase.Load
If SelfEvaluationReportBAR.Value = (0) Then
FeelingLBL.Text = "Please select a value."
End If
If SelfEvaluationReportBAR.Value = (1,25) Then
FeelingLBL.Text = "I am starting to develop my ability to perform this task."
End If
If SelfEvaluationReportBAR.Value = (26,50) Then
FeelingLBL.Text = "I feel improvement in my ability to perform this task."
End If
If SelfEvaluationReportBAR.Value = (51,75) Then
FeelingLBL.Text = "My confidence in my ability to perform this task is substantial."
End If
If SelfEvaluationReportBAR.Value = (76,100) Then
FeelingLBL.Text = "I feel fully confident in my ability to efficiently and accurately perform the day to day tasks that are assigned to me."
End If
End Sub
问题是,每当我尝试设置范围时,都会出现以下错误:
错误 BC30452 运算符“=”未为类型“整数”和“(整数,整数)”定义。
我想我的格式有误。有没有人对范围可以/应该如何格式化有任何想法?
这是我当前的 TrackBar 设置:
Private Sub SelfEvaluationReportBAR_Scroll(sender As Object,e As EventArgs) Handles MyBase.Load
SelfEvaluationReportBAR.Minimum = 0
SelfEvaluationReportBAR.Maximum = 100
SelfEvaluationReportBAR.SmallChange = 1
SelfEvaluationReportBAR.LargeChange = 5
SelfEvaluationReportBAR.TickFrequency = 5
End Sub
End Class
解决方法
有很多方法来完成你的任务。
第一次
If SelfEvaluationReportBAR.Value >= 1 AndAlso SelfEvaluationReportBAR.Value <= 25) Then
FeelingLBL.Text = "I am starting to develop my ability to perform this task."
End If
第二个
Select case SelfEvaluationReportBAR.Value
Case 0
....
Case 1 To 25
FeelingLBL.Text = "I am starting to develop my ability to perform this task."
Case 26 To 50
...
' Other case follow
End Select
第三
If Enumerable.Range(1,25).Contains(c) Then
FeelingLBL.Text = "I am starting to develop my ability to perform this task."
End If
想到的就是这些,可能还有其他的。
前两个例子是最基本的方法和只用五个范围我会留在简单如果一个。第三个是只是为了显示多少种方式存在,但我真的不建议只建立一个枚举范围来检查,如果数载。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。