我有这段代码:
Public Class Form1
Private _Previous As System.Nullable(Of Point) = Nothing
Private Sub pictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
_Previous = e.Location
pictureBox1_MouseMove(sender, e)
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
Dim Marker As Integer
Marker = Lst_Markers.SelectedIndex + 1
If _Previous IsNot Nothing Then
For i As Integer = 0 To Marker
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
PictureBox1.Image = bmp
Next
Select Case Lst_Markers
Case 1
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.FillEllipse(Brushes.Red, e.X, e.Y, 10, 10)
End Using
Case 2
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.FillEllipse(Brushes.Yellow, e.X, e.Y, 10, 10)
End Using
Case 3
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.FillEllipse(Brushes.Green, e.X, e.Y, 10, 10)
End Using
Case 4
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.FillEllipse(Brushes.Blue, e.X, e.Y, 10, 10)
End Using
Case Else
MsgBox("Select a marker")
End Select
PictureBox1.Invalidate()
_Previous = e.Location
End If
End Sub
Private Sub pictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
_Previous = Nothing
End Sub
End Class
但是我在问题标题中收到错误。问题是“案例1”,“案例2”,“案例3”,“案例4”的陈述,我想知道我做错了什么,我认为问题在于我的问题 Marker = Lst_Markers.SelectedIndex + 1 这是对的吗?
答案 0 :(得分:1)
您的意思是Select Case Marker
而不是Select Case Lst_Markers
吗?
您无法将Lst_Markers
与Case
语句中的整数进行比较 - 将控件与整数进行比较是没有意义的。如果您想比较所选索引,Marker
似乎就是您要比较的内容。
答案 1 :(得分:0)
尝试在select语句中使用整数变量。
Select Case Marker
而不是:
Select Case Lst_Markers
答案 2 :(得分:0)
LST_Markers
是ListBox
,无法与整数进行比较。我认为你的案例陈述中的意思是LST_Markers.selectedIndex
。
答案 3 :(得分:0)
我无法肯定地说,因为Lst_Markers没有在您引用的代码中定义,但是如果出现错误,则会出现Lst_Markers是Listbox。列表框不是整数,那么Select Case Lst_Markers是什么意思?我不认为这是你想要选择的变量。 (你可能意味着马克。)
答案 4 :(得分:0)
为什么不使用:Select Case Lst_Markers.SelectedIndex + 1
但出于好奇,你们每个循环的功能是什么?
For i As Integer = 0 To Marker
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
PictureBox1.Image = bmp
Next
我真的没有看到这样做的几点,例如:
如果你选择绿色,直到运行5次,如果你选择红色,那么只运行两次。
我测试了你的代码,没有For For look,只有两行:
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
PictureBox1.Image = bmp
代码似乎与在每个循环中的代码相同。