按下“取消”按钮时出现问题在OpenFileDialog中 [英] Problem when pressed "cancel" in OpenFileDialog
问题描述
Vb.net 2005快递我一直在努力,问题是:我用
openfiledialog来浏览文件,我创建了一些代码来执行文件
用OK按钮,没问题。但如果我按取消按钮作为openfiledialog框的
结果,例如我的文件名''被添加到
列表框中,或者我的音频文件从头开始播放。
更好地解释:
openfileplaylist.ShowDialog()
ListBox1.Items.Add(openfileplaylist.FileName)
1 - 如果单击确定,该代码会将文件路径添加到列表框中,但是如果我单击
" cancel"它添加了OpenFileDialog1文本到列表框中。为什么?
2 - 我还希望我的文件仅作为文件名列出,而不是完整的路径,如
c:\ blabla \ blaba \ kklj \ bla.mp3。
这2个问题对我来说非常重要。
感谢您的回答。
Hi,
Vb.net 2005 express i''ve been working, the problem is: I use
openfiledialog to browse files, i created some code to execute file
with OK button, no problem. But if i press "cancel" button as the
result of openfiledialog box, for example my filename''s are added into
listbox or my audio file is being played from the beginning.
To explain better:
openfileplaylist.ShowDialog()
ListBox1.Items.Add(openfileplaylist.FileName)
1-That code adds file path into list box if click OK, but if i click
"cancel" it adds "OpenFileDialog1" text into listbox. Why?
2-Also i want my files listed only as "filenames", not full path like
c:\blabla\blaba\kklj\bla.mp3.
These 2 questions are very important for me.
Thanks for the answer from now.
推荐答案
" kimiraikkonen"写道:
"kimiraikkonen" wrote:
Vb.net 2005表示我一直在工作,问题是:我用
openfiledialog浏览文件,我用OK按钮创建了一些代码来执行文件
,没问题。但如果我按取消按钮作为openfiledialog框的
结果,例如我的文件名''被添加到
列表框中,或者我的音频文件从头开始播放。
更好地解释:
openfileplaylist.ShowDialog()
ListBox1.Items.Add(openfileplaylist.FileName)
1 - 如果单击确定,该代码会将文件路径添加到列表框中,但是如果我单击
" cancel"它添加了OpenFileDialog1文本到列表框中。为什么?
2 - 我还希望我的文件仅作为文件名列出,而不是完整的路径,如
c:\ blabla \ blaba \ kklj \ bla.mp3。
这2个问题对我来说非常重要。
感谢您的回答。
Hi,
Vb.net 2005 express i''ve been working, the problem is: I use
openfiledialog to browse files, i created some code to execute file
with OK button, no problem. But if i press "cancel" button as the
result of openfiledialog box, for example my filename''s are added into
listbox or my audio file is being played from the beginning.
To explain better:
openfileplaylist.ShowDialog()
ListBox1.Items.Add(openfileplaylist.FileName)
1-That code adds file path into list box if click OK, but if i click
"cancel" it adds "OpenFileDialog1" text into listbox. Why?
2-Also i want my files listed only as "filenames", not full path like
c:\blabla\blaba\kklj\bla.mp3.
These 2 questions are very important for me.
Thanks for the answer from now.
您好,
请尝试以下代码:
Dim openfileplaylist As New OpenFileDialog
....
如果openfileplaylist.ShowDialog()= DialogResult.OK那么
Dim temp_string As String
Dim a As Integer
temp_string = openfileplaylist.FileName
''删除.mp3
temp_string = temp_string.Substring(0,temp_string.Length - 4)
''找到最后的位置" \"
a = temp_string.LastIndexOf(" \")
'''普通文件名
temp_string = temp_string.Substring(a + 1)
ListBox1.Items.Add(temp_string)
其他
女士gBox(没有加载文件。)
结束如果
问候,
Oliver
Hello,
Please try this code:
Dim openfileplaylist As New OpenFileDialog
....
If openfileplaylist.ShowDialog() = DialogResult.OK Then
Dim temp_string As String
Dim a As Integer
temp_string = openfileplaylist.FileName
''remove the .mp3
temp_string = temp_string.Substring(0, temp_string.Length - 4)
''find position of last "\"
a = temp_string.LastIndexOf("\")
''retrieve the plain file name
temp_string = temp_string.Substring(a + 1)
ListBox1.Items.Add(temp_string)
Else
MsgBox("No file was loaded.")
End If
Regards,
Oliver
你肯定向OP展示了一个实现他想要的东西的方式,但是更简单的方法是:
更简单:
如果openfileplaylist.ShowDialog()= DialogResult.OK那么
ListBox1.Items.Add(Path.GetFileName(openfileplayli st.FileName))
否则
MsgBox(没有加载文件。)
结束如果
Oliver Tell < Ol ******** @ discussion.microsoft.com写信息
新闻:A5 ******************** ************** @ microsof t.com ...
Youv''e certainly shown the OP a ''way'' to achieve what he wants but a much
simpler way would be:
If openfileplaylist.ShowDialog() = DialogResult.OK Then
ListBox1.Items.Add(Path.GetFileName(openfileplayli st.FileName))
Else
MsgBox("No file was loaded.")
End If
"Oliver Tell" <Ol********@discussions.microsoft.comwrote in message
news:A5**********************************@microsof t.com...
" kimiraikkonen"写道:
"kimiraikkonen" wrote:
>
Vb.net 2005表示我一直在工作,问题是:我用
openfiledialog来浏览文件,我用OK按钮创建了一些执行文件的代码,没问题。但如果我按取消按钮作为openfiledialog框的结果,例如我的文件名被添加到
列表框中,或者我的音频文件从头开始播放。
要更好地解释:
openfileplaylist.ShowDialog()
ListBox1.Items.Add(openfileplaylist.FileName)
1 - 如果单击OK,该代码会将文件路径添加到列表框中,但是如果我点击
取消它添加了OpenFileDialog1文本到列表框中。为什么?
2 - 我还希望我的文件仅列为文件名,而不是完整的路径,如
c:\ blabla \ blaba \ kklj \ bla.mp3。
这两个问题对我来说非常重要。
感谢您的回答。
>Hi,
Vb.net 2005 express i''ve been working, the problem is: I use
openfiledialog to browse files, i created some code to execute file
with OK button, no problem. But if i press "cancel" button as the
result of openfiledialog box, for example my filename''s are added into
listbox or my audio file is being played from the beginning.
To explain better:
openfileplaylist.ShowDialog()
ListBox1.Items.Add(openfileplaylist.FileName)
1-That code adds file path into list box if click OK, but if i click
"cancel" it adds "OpenFileDialog1" text into listbox. Why?
2-Also i want my files listed only as "filenames", not full path like
c:\blabla\blaba\kklj\bla.mp3.
These 2 questions are very important for me.
Thanks for the answer from now.
您好,
请尝试以下代码:
Dim openfileplaylist As New OpenFileDialog
...
如果openfileplaylist.ShowDialog()= DialogResult.OK然后
Dim temp_string As String
Dim a As Integer
temp_string = openfileplaylist.FileName
''删除.mp3
temp_string = temp_string.Substring(0,temp_string.Length - 4)
''找到最后一个位置'\\ \\"
a = temp_string.LastIndexOf(" \")
''检索普通文件名
temp_string = temp_string。子串(a + 1 )
ListBox1.Items.Add(temp_string)
Else
MsgBox(没有加载文件。)
结束如果
问候,
Oliver
Hello,
Please try this code:
Dim openfileplaylist As New OpenFileDialog
...
If openfileplaylist.ShowDialog() = DialogResult.OK Then
Dim temp_string As String
Dim a As Integer
temp_string = openfileplaylist.FileName
''remove the .mp3
temp_string = temp_string.Substring(0, temp_string.Length - 4)
''find position of last "\"
a = temp_string.LastIndexOf("\")
''retrieve the plain file name
temp_string = temp_string.Substring(a + 1)
ListBox1.Items.Add(temp_string)
Else
MsgBox("No file was loaded.")
End If
Regards,
Oliver
1。检查ShowDialog的返回值。如果它的DialResult.OK,你的
处理。
2.要获得文件名,请使用System.Io.Path.GetFilename(fullpath)
---------
- G Himangi,Sky Software http://www.ssware.com
Shell MegaPack:用于Drop-In Windows资源管理器的GUI控件如Shell
为您的应用程序浏览功能(.Net和ActiveX版本)。
EZNamespaceExtensions.Net:在.Net中快速开发名称空间扩展
EZShellExtensions.Net:开发所有外壳扩展,资源管理器和BHO
快速进入.Net
---------
kimiraikkonen < ki ************* @ gmail.comwrote in message
news:11 ***************** ****@k79g2000hse.googlegro ups.com ...
1. Check the return value of ShowDialog. If its DialResult.OK, do your
processing.
2. To get just the file name, use System.Io.Path.GetFilename(fullpath)
---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
---------
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
Vb.net 2005表示我去过工作,问题是:我用
openfiledialog来浏览文件,我创建了一些代码来执行文件
用OK按钮,没问题。但如果我按取消按钮作为openfiledialog框的
结果,例如我的文件名''被添加到
列表框中,或者我的音频文件从头开始播放。
更好地解释:
openfileplaylist.ShowDialog()
ListBox1.Items.Add(openfileplaylist.FileName)
1 - 如果单击确定,该代码会将文件路径添加到列表框中,但是如果我单击
" cancel"它添加了OpenFileDialog1文本到列表框中。为什么?
2 - 我还希望我的文件仅作为文件名列出,而不是完整的路径,如
c:\ blabla \ blaba \ kklj \ bla.mp3。
这2个问题对我来说非常重要。
感谢您的回答。
Hi,
Vb.net 2005 express i''ve been working, the problem is: I use
openfiledialog to browse files, i created some code to execute file
with OK button, no problem. But if i press "cancel" button as the
result of openfiledialog box, for example my filename''s are added into
listbox or my audio file is being played from the beginning.
To explain better:
openfileplaylist.ShowDialog()
ListBox1.Items.Add(openfileplaylist.FileName)
1-That code adds file path into list box if click OK, but if i click
"cancel" it adds "OpenFileDialog1" text into listbox. Why?
2-Also i want my files listed only as "filenames", not full path like
c:\blabla\blaba\kklj\bla.mp3.
These 2 questions are very important for me.
Thanks for the answer from now.
这篇关于按下“取消”按钮时出现问题在OpenFileDialog中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!