vb.net - 有没有办法根据 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 运算符 '=' 没有为类型 'Integer' 和 '(Integer, Integer)' 定义。
我认为我的格式错误。有没有人对范围可以/应该如何格式化有任何想法?
这是我当前对 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
这些是想到的方式,可能还有其他方式。
前两个示例是最基本的方法,只有五个范围,我会使用简单的 If 一个。第三个只是显示有多少种方法存在,但我真的不建议建立一个可枚举的范围来检查是否包含一个数字。
推荐阅读
- javascript - 通过数组 ReactJS 映射时未显示下拉菜单
- docker - 来自 Grafana 的电子邮件警报在 docker 容器内不起作用
- reactjs - 模拟渲染道具 React Component with Jest
- java - 函数在 drools 中返回不正确的布尔值
- angularjs - AngularJS $routeParams:设置 $scope 变量
- asp.net - robocopy 是一种将网站发布到多台服务器上的有效工具吗?
- javafx - 如何使用 Griffon 将图标放入文件菜单?
- php - 将 JSON 对象转换为关联的 php 数组
- django - 添加环境变量以激活 Django 项目的 virtualenv 中的文件
- java - 奥利奥后台服务