前端之家收集整理的这篇文章主要介绍了
[VB.NET]OpenFileDialog问题,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
OpenFileDialog问题 If OpenFileDialog1.ShowDialog = DialogResult.Cancel Then Exit Sub End If 请问为什么两次点击取消才能取消,而savefiledialog确没有问题, 请问如何
解决谢谢 __________________________________________________________________________ If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub End If 应该不是这三行的问题,请多贴些
代码。 __________________________________________________________________________ Try Dim myreader = New System.IO.StreamReader(myfilename,System.Text.Encoding.Default) Dim myreceiver As String = myreader.readline While Not myreceiver Is Nothing RichText
Box1.AppendText(myreceiver & vbCrLf) myreceiver = myreader.readline End While Catch ex As Exception Message
Box.Show(ex.Message,"error ",Message
BoxButtons.OK,Message
BoxIcon.Information) End Try 感谢楼上确实因为上面的
代码,应怎样改呢? __________________________________________________________________________ 可能需要filname的定义和赋值部分。 __________________________________________________________________________ 我是说myfilename。 __________________________________________________________________________ Dim result As DialogResult With Me.OpenFileDialog1 .Title = "Open " .CheckFileExists = True .CheckPathExists = True .Filter = "all(*.txt)|*.txt " .ShowDialog() myfilename = .FileName End With If result = OpenFileDialog1.ShowDialog.Cancel Then ''If OpenFileDialog1.ShowDialog = DialogResult.Cancel Then Exit Sub End If RichText
Box1.Text = " " Try Dim myreader = New System.IO.StreamReader(myfilename,Message
BoxIcon.Information) End Try __________________________________________________________________________ 我上面用了两种判断
效果都一样,自己试了是由于 Dim myreader = New System.IO.StreamReader(myfilename,System.Text.Encoding.Default) 此部分要求
文件名不能为空,所引起的,不知道怎么
解决 __________________________________________________________________________ 您用了两次ShowDialog,所以会出现两次,(在判断时用ShowDialog和在别处用是一样的) 我帮您把
代码改了一下,容易看些: Public Class Form1 Private Sub Button1_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles Button1.Click Dim myfilename As String = " " With Me.OpenFileDialog1 .Title = "Open " .CheckFileExists = True .CheckPathExists = True .Filter = "all(*.txt)|*.txt " .FileName = " " End With If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then RichText
Box1.Text = " " myfilename = Me.OpenFileDialog1.FileName Try Dim myreader = New System.IO.StreamReader(myfilename,Message
BoxIcon.Information) End Try End If End Sub End Class __________________________________________________________________________ 谢谢我也发现这个问题了,非常感谢 __________________________________________________________________________ 赶时间忙得头脑发热了哈哈 __________________________________________________________________________