[英]How can I open a File Explorer window from a Visual Studio app and set the position and size?
[英]How can I use the Open With function in File explorer to open a text file in my application?
我正在用 Visual Basic 編寫一個文本編輯器。 它主要工作,但我希望能夠在資源管理器中單擊 *.txt 文件並選擇打開方式以在我的程序中打開它。 我該如何實施?
你真的不需要所有的文件資源管理器來完成這個。 使用OpenFileDialog
class。 您可以將文件讀入文本框中。 確保您使用的文本框的 Multiline 設置為 True。
Private Sub OpenFileInTextBox()
Dim OFD As New OpenFileDialog
OFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
OFD.Filter = "Text Files (*.txt)|*.txt"
Dim fileSelected As String = ""
If OFD.ShowDialog() = DialogResult.OK Then
fileSelected = OFD.FileName
Else
MessageBox.Show("Not file selected")
Exit Sub
End If
TextBox1.Text = File.ReadAllText(fileSelected)
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.