Reputation: 1197
I have a list with these words { AutoSize,Normal,StretchImage,CenterImage,Zoom }
Firstly my users will select one item from the list and after i need to change the property SizeMode of my picture box as their selection.
Can i make something without use of if/switch-case statements ?
If (size_mode_list.SelectedText = "AutoSize") Then
picture_box.SizeMode = PictureBoxSizeMode.AutoSize
ElseIf (size_mode_list.SelectedText = "Normal") Then
picture_box.SizeMode = PictureBoxSizeMode.Normal
ElseIf (size_mode_list.SelectedText = "StretchImage") Then
picture_box.SizeMode = PictureBoxSizeMode.StretchImage
ElseIf (size_mode_list.SelectedText = "CenterImage") Then
picture_box.SizeMode = PictureBoxSizeMode.CenterImage
ElseIf (size_mode_list.SelectedText = "Zoom") Then
picture_box.SizeMode = PictureBoxSizeMode.Zoom
End If
Upvotes: 0
Views: 300
Reputation: 38875
Can i make something without use of if/switch-case statements
One way is to fill the CBO with the Enum names:
cbo.Items.AddRange([Enum].GetNames(GetType(PictureBoxSizeMode)))
Then parse the result:
pb.SizeMode = CType([Enum].Parse(GetType(PictureBoxSizeMode), cbo.Text),
PictureBoxSizeMode)
Use .Text
or SelectedItem.ToString()
and the cbo should be a DropDownList so the user cant type something in.
You could also write a small Name-ValuePair class to store the Name and Values to a List, then use the ValueMember
property to set the size mode so you are working off the Enum Value rather than the Name.
Upvotes: 3