我正在创建一个具有TextBox的应用程序,当用户输入文件名时,它会尝试更新PictureBox。
它有一个预设目录,所有用户都将使用该目录,该目录位于共享网络文件夹中。它还会检查用户是否输入了整个路径和文件名,它会相应地显示图像。
但是,如果用户开始输入“C:\ Filename ...”代码,代码将起作用,代码将在“C:”之后挂起几秒钟。我遇到的更大问题是,如果用户断开与网络驱动器的连接,应用程序将继续寻找它10或20秒,这是没有必要的,我宁愿停止尝试,如果它没有看到它2秒。
Dim myCallback As New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
'If the user's entry exists as a filename, display it in the picturebox
If Dir(txtGrab.Text) <> "" Then
Dim myBitmap As New Bitmap(txtGrab.Text)
Dim myThumbnail As Image = myBitmap.GetThumbnailImage(myBitmap.Width, myBitmap.Height, myCallback, IntPtr.Zero)
myThumbnail.GetThumbnailImage(BorderSize, BorderSize, myCallback, IntPtr.Zero)
imgDisplay.Image = myThumbnail
End If
'If the user's entry exists within intranet's path, display in picturebox
If Dir("\\Intranet\Images\" & txtGrab.Text & ".tif") <> "" Then
Dim myBitmap As New Bitmap("\\Intranet\" & txtGrab.Text & ".tif")
Dim myThumbnail As Image = myBitmap.GetThumbnailImage(myBitmap.Width, myBitmap.Height, myCallback, IntPtr.Zero)
myThumbnail.GetThumbnailImage(BorderSize, BorderSize, myCallback, IntPtr.Zero)
frmCodeGrabber.imgDisplay.Image = myThumbnail
End If