更新以包含更多代码。
vb.net 2012 给我下面的代码三个警告,说未使用的变量。temp、filetype 和 inde 都被警告为未使用。
Private Sub Next_Image()
' TO Do - is same, maybe make a function? Don't know if its worth it though
msgbox(My.Computer.FileSystem.GetFileInfo(img_picture.ImageLocation).Extension)
exit sub
If changes = True Then
If filesettings(2) = 0 Then
If MessageBox.Show("Save Changes?", "Save Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim filetype As System.Drawing.Imaging.ImageFormat
If My.Computer.FileSystem.GetFileInfo(img_picture.ImageLocation).Extension.ToLower = ".png" Then
filetype = System.Drawing.Imaging.ImageFormat.Png
ElseIf My.Computer.FileSystem.GetFileInfo(img_picture.ImageLocation).Extension.ToLower = ".jpg" OrElse My.Computer.FileSystem.GetFileInfo(img_picture.ImageLocation).Extension.ToLower = ".jpeg" Then
filetype = System.Drawing.Imaging.ImageFormat.Jpeg
ElseIf My.Computer.FileSystem.GetFileInfo(img_picture.ImageLocation).Extension.ToLower = ".bmp" Then
filetype = System.Drawing.Imaging.ImageFormat.Bmp
ElseIf My.Computer.FileSystem.GetFileInfo(img_picture.ImageLocation).Extension.ToLower = ".gif" Then
filetype = System.Drawing.Imaging.ImageFormat.Gif
ElseIf My.Computer.FileSystem.GetFileInfo(img_picture.ImageLocation).Extension.ToLower = ".tiff" Then
filetype = System.Drawing.Imaging.ImageFormat.Tiff
End If
img_picture = Nothing
imageadjust.Save(filename, filetype)
End If
End If
End If
If Not img_picture.ImageLocation = Nothing Then
Dim inde As Integer = files.IndexOf(filename)
If inde = files.Count - 1 Then
img_picture.ImageLocation = files(0)
Else
img_picture.ImageLocation = files(inde + 1)
End If
filename = img_picture.ImageLocation
Me.Text = filename.Substring(filename.LastIndexOf("\") + 1) & " - Picture Viewer"
If filesettings(0) = 1 Then
img_picture.SizeMode = PictureBoxSizeMode.CenterImage
ElseIf filesettings(0) = 2 Then
img_picture.SizeMode = PictureBoxSizeMode.Zoom
Else
Dim temp As New Bitmap(filename)
Me.img_picture.Refresh()
If temp.Width > Me.img_picture.Width OrElse temp.Height > Me.img_picture.Height Then
Me.img_picture.SizeMode = PictureBoxSizeMode.Zoom
Else
Me.img_picture.SizeMode = PictureBoxSizeMode.CenterImage
End If
temp.Dispose()
End If
End If
End Sub
请原谅代码,我刚刚开始添加一些东西,所以有些可能是多余的。但是我不明白为什么 temp、inde 和 filetype 被声明为未使用。