Reputation:
I have this code:
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
However I am getting the error in my question title. The problem is the 'Case 1', 'Case 2', 'Case 3', 'Case 4' statements, I am wondering what I've done wrong, and I think the problem lies in my Marker = Lst_Markers.SelectedIndex + 1 line, is this right?
Upvotes: 1
Views: 2583
Reputation: 486
Why don't you just get rid of Marker all together by using: Select Case Lst_Markers.SelectedIndex + 1
But just out of curiosity what is the function of the For each loop you have?
For i As Integer = 0 To Marker
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
PictureBox1.Image = bmp
Next
I really don't see the point in doing this several times, for example:
If you chose green this till run 5 times, where if you chose red this will only run twice.
I tested out your code without the For each look and only had the two lines:
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
PictureBox1.Image = bmp
The code seems to work just the same as if it was in a For each loop.
Upvotes: 0
Reputation: 2698
I can't say for sure, as Lst_Markers isn't defined in the code you quoted, but given the error, it would appear Lst_Markers is a Listbox. Listboxes aren't integers, so what does Select Case Lst_Markers mean? I don't think that's the variable you intended to select on. (You probably meant Marker.)
Upvotes: 0
Reputation: 3834
LST_Markers
is a ListBox
and cant be compared to a integer. I think you meant LST_Markers.selectedIndex
in your case statement.
Upvotes: 0
Reputation: 191
Try using your integer variable in the select statement.
Select Case Marker
instead of:
Select Case Lst_Markers
Upvotes: 0
Reputation: 281695
Did you mean Select Case Marker
rather than Select Case Lst_Markers
?
You can't compare Lst_Markers
with the integers in your Case
statements - comparing a control with an integer is meaningless. If you want to compare the selected index, Marker
seems like what you should be comparing with.
Upvotes: 2