* 電腦環境:Windows 7 64bit *
* Microsoft Visual Studio版本:2010 Professional *
****************************************
一、開啟Visual Studio開新專案
View > Toolbox > 拖曳1個TextBox或MaskedTextBox+2個Button到Form視窗中
分別修改它們的名稱如下↓
Private btntbmapping As New Hashtable
Private Sub CurrentUSPC_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'設定textbox和button的關係
btntbmapping.Add(Me.btnFileChoose_Current, Me.tbFileName_Current)
End Sub
Private Sub btnFileChoose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileChoose_Current.Click
Dim effectTB As TextBox = CType(btntbmapping.Item(CType(sender, Button)), TextBox)
Dim OpenFileDialog2 As New OpenFileDialog
OpenFileDialog2.InitialDirectory = "\\120.100.39.66\Related\更新檔\"
If Not Directory.Exists(OpenFileDialog2.InitialDirectory) Then
MessageBox.Show("目錄不存在")
End If
OpenFileDialog2.Filter = "文字檔 (*.txt)|*.txt"
OpenFileDialog2.Multiselect = False
OpenFileDialog2.ShowDialog()
effectTB.Text = OpenFileDialog2.FileName
End Sub
Private Sub btnFileTrans_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileTrans.Click
Dim InFile As New FileInfo(tbFileName_Current.Text)
SaveFileDialog1.Filter = "txt |*.txt"
SaveFileDialog1.Title = "Save an txt File"
SaveFileDialog1.FileName = "New-" & InFile.Name.Split(".")(0)
SaveFileDialog1.ShowDialog()
Dim th As Thread = New Thread(AddressOf TransFormFile)
th.Start(tbFileName_Current.Text)
End Sub
Private Sub TransFormFile(ByVal filePath As String, Optional ByVal Errinfo As String = "")
'do something
End Sub
程式碼的意思是點下btnFileChoose_Current按鈕時,會跳出預設路徑的開啟檔案視窗,類似這樣↓
選了檔案之後,由於
btntbmapping As New Hashtable
'設定textbox和button的關係
btntbmapping.Add(Me.btnFileChoose_Current, Me.tbFileName_Current)
的設定,會將檔案路徑由tbFileName_Current顯示
點btnFileTrans(就是「另存」button)後,會自動帶新檔名
按下存檔後,便開始跑Thread
沒有留言:
張貼留言