[VB.NET]OpenFileDialog问题

前端之家收集整理的这篇文章主要介绍了[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 RichTextBox1.AppendText(myreceiver & vbCrLf) myreceiver = myreader.readline End While Catch ex As Exception MessageBox.Show(ex.Message,"error ",MessageBoxButtons.OK,MessageBoxIcon.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 RichTextBox1.Text = " " Try Dim myreader = New System.IO.StreamReader(myfilename,MessageBoxIcon.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 RichTextBox1.Text = " " myfilename = Me.OpenFileDialog1.FileName Try Dim myreader = New System.IO.StreamReader(myfilename,MessageBoxIcon.Information) End Try End If End Sub End Class __________________________________________________________________________ 谢谢我也发现这个问题了,非常感谢 __________________________________________________________________________ 赶时间忙得头脑发热了哈哈 __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/263916.html

猜你在找的VB相关文章