我想使用openfiledialog使用以下代码在图片框中显示doc文件,但是会出错 [英] I want to show the doc file in picture box using following code using openfiledialog ,but gets error
问题描述
Private Sub cmdMemberImage_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理cmdMemberImage.Click
OpenFileDialog1.FileName =
OpenFileDialog1.Filter =所有格式| * .pdf; * .jpeg; * .doc; *。jpg; * .bmp; * .docx; * .xls; * .xlsx'所有格式| * .JPG; * .JPEG; * .JPE; * BMP,* RLE; * DIB; * PNG | JPEG。(* JPG; *。JPEG; * JPE)| * .JPG; * JPEG; * JPE | BMP(*。 BMP; * .RLE; * .DIB)| * .BMP; * .RLE; * .DIB | PNG(* .PNG)| * .PNG
试试
如果OpenFileDialog1.ShowDialog = DialogResult.OK那么
'Dim imagepath As String = OpenFileDialog1.FileName.ToString
Dim fileName As String
fileName = OpenFileDialog1.FileName
'FileIO.FileSystem.CurrentDirectory = Path.GetFileName(fileName)
Dim str As String
str = Path.GetFileName(fileName)
'Di m image1 As FileSystem = FileSystem.FromFile(fileName)
PictureBoxMemberImage.Image = str
否则
'cmdHallImage.Focus()
结束如果
Catch ex As例外
MsgBox(由于某些问题,图片尚未保存!,vbCritical,错误)
结束尝试
End Sub
Private Sub cmdMemberImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMemberImage.Click
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "All Format|*.pdf;*.jpeg;*.doc;*.jpg;*.bmp;*.docx;*.xls;*.xlsx" 'All Format|*.JPG;*.JPEG;*.JPE;*.BMP;*.RLE;*.DIB;*.PNG|JPEG(*.JPG;*.JPEG;*.JPE)|*.JPG;*.JPEG;*.JPE|BMP(*.BMP;*.RLE;*.DIB)|*.BMP;*.RLE;*.DIB|PNG(*.PNG)|*.PNG
Try
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
' Dim imagepath As String = OpenFileDialog1.FileName.ToString
Dim fileName As String
fileName = OpenFileDialog1.FileName
'FileIO.FileSystem.CurrentDirectory = Path.GetFileName(fileName)
Dim str As String
str = Path.GetFileName(fileName)
' Dim image1 As FileSystem = FileSystem.FromFile(fileName)
PictureBoxMemberImage.Image = str
Else
'cmdHallImage.Focus()
End If
Catch ex As Exception
MsgBox("Image has not been saved due to some problems !", vbCritical, "Error")
End Try
End Sub
推荐答案
要做的第一件事是停止丢弃您的错误信息:您使用try ... catch
阻止,你捕获所有错误,但是......然后你扔掉了解决问题所需的信息,但报告了一个香草由于某些问题而没有保存图像!消息,没有系统为您提供的任何信息。
因此更改错误报告:
The first thing to do is to stop throwing away your error information: you use atry...catch
block, and you catch all errors, but...you then throw away the information you need to solve the problem, but reporting a vanilla "Image has not been saved due to some problems !" message, without any of the info that the system provides you.
So change the error reporting:
MsgBox("Image has not been saved. The system reported: " & ex.Message, vbCritical, "Error")
作为绝对最小值。这会将系统发现的错误传递给用户,为他们(以及您)提供少量信息以开始解决问题。
如果不是帮助,然后在MsgBox行上放置一个断点,并使用调试器检查异常对象,它将包含更多细节。
碰巧,你的错误是非常明显,但是当你收到实际的错误信息时你应该看到它!
as the absolute minimum. This passes the error that the system found to the user, giving them (and you) a small amount of information to begin solving the problem.
If that doesn't help, then put a breakpoint on the MsgBox line, and use the debugger to examine the exception object, which will contain more detail.
As it happens, your mistake is pretty obvious, but you should see that when you get the actual error message to play with!
这篇关于我想使用openfiledialog使用以下代码在图片框中显示doc文件,但是会出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!