本文介绍了1个OpenFileDialog,用于4个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有四个文本框和四个按钮
如何使用一个OpenFileDialog1进行4个按钮控件..?
谢谢
以下是代码..
I have four textboxes and four buttons
how can I use one OpenFileDialog1 for 4 button controls..?
thanks
below is the code ..
Private Sub btn_ClientSelectTemplate_0_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_0.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub btn_ClientSelectTemplate_1_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_1.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub btn_ClientSelectTemplate_2_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_2.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub btn_ClientSelectTemplate_3_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_3.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
'' --- Gives the full path of file name
Me.txtClientProject_0.Text = OpenFileDialog1.FileName
'' --- Gives only the file name
'Me.txtClientProject_0.Text = Path.GetFileName(OpenFileDialog1.FileName)
End Sub
Private Sub OpenFileDialog2_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog2.FileOk
txtClientProject_1.Text = OpenFileDialog2.FileName
End Sub
Private Sub OpenFileDialog3_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog3.FileOk
txtClientProject_2.Text = OpenFileDialog3.FileName
End Sub
Private Sub OpenFileDialog4_FileOk(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog4.FileOk
txtClientProject_3.Text = OpenFileDialog4.FileName
End Sub
推荐答案
Private Sub btn_ClientSelectTemplate_0_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_0.Click
OpenFileDialog1.ShowDialog()
Me.txtClientProject_0.Text = OpenFileDialog1.FileName
'' --- Gives only the file name
'Me.txtClientProject_0.Text = Path.GetFileName(OpenFileDialog1.FileName)
End Sub
Private Sub btn_ClientSelectTemplate_1_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_1.Click
OpenFileDialog1.ShowDialog()
txtClientProject_1.Text = OpenFileDialog2.FileName
End Sub
Private Sub btn_ClientSelectTemplate_2_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_2.Click
OpenFileDialog1.ShowDialog()
txtClientProject_2.Text = OpenFileDialog3.FileName
End Sub
Private Sub btn_ClientSelectTemplate_3_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClientSelectTemplate_3.Click
OpenFileDialog1.ShowDialog()
txtClientProject_3.Text = OpenFileDialog4.FileName
End Sub
这篇关于1个OpenFileDialog,用于4个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!