如何在记事本文件中编辑文本框?

时间:2019-12-26 02:55:07

标签: vb.net textbox edit notepad

我正在VB.net(Visual Studio)中构建一个小型桌面应用程序,对此我感到很挣扎。

我想在记事本文件中编辑一个文本框。该文件将打开并保存在我的PC桌面上,但是当我在文本框中写入内容时,该文件不会发送到记事本。记事本保持空白... 到目前为止,在下面的代码中。

Private Sub BtnEditQuestion_Click_1(sender As Object, e As EventArgs) Handles BtnEdiPla.Click
    MsgBox("Now, a notepad will be openned. Edit the question on the file.")
    Dim desktop_path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    Dim writer As TextWriter = New StreamWriter(ruta_escritorio + "\planteamiento.txt")
    writer.Write(TxtPla.Text)
    Process.Start(desktop_path + "\planteamiento.txt")
End Sub

(我还有另一个按钮,它将要求用户上传文本文件,以便文本框填充其内容...如果有人知道在一个按钮中同时完成两项工作,那么也很好)

2 个答案:

答案 0 :(得分:0)

尝试以下操作:txtBox.Text = = File.ReadAllText(path)

答案 1 :(得分:0)

我不认为您真的想一次在程序和记事本中显示文件。如果用户想在您的程序中对其进行编辑,则需要2个单独的事件。

我使用了<div class="col-md-8 d-flex" style="margin-top: -25px"> <select name="carlist" form="carform" class="form-control" id="exploreNeighbour" style="z-index: 2"> <option value="">I have no idea</option> {% for venue in venue_category %} <option value="{{ venue.name }}">{{ venue.name }}</option> {% endfor %} </select> <i class="fas fa-chevron-down" style="pointer-events: none; z-index: 1; margin-right: 20px"></i> </div> 中的File对象。流需要关闭和处理。 System.IO.ReadAllText将为您打开和关闭文件。

.WriteAllText

如果要查看记事本中所做的更改,则必须将文件保存在记事本中,并在程序中再次单击Button1以查看更改。

相关问题