【问题标题】:How to take the value of multiple textbox's and create one rich textbox(to save as a .txt) VB.NET如何获取多个文本框的值并创建一个富文本框(保存为.txt)VB.NET
【发布时间】:2015-12-21 00:12:35
【问题描述】:

我想知道如何获取几个文本框(具有用户估算的值)并将它们放在一起以使一大块文本变成.txt。我特别想制作一个吉他标签应用程序。

我已经创建了基本设计,但我需要帮助来保存它。我放了一个菜单条来保存。当用户单击时,它会打开一个带有富文本框的表单。

我的问题:我希望它采用文本框,按特定顺序对其进行格式化,然后将它们添加到富文本框中,以后可以将它们另存为 .txt。

请随时提出任何问题以澄清我的情况。谢谢。

【问题讨论】:

    标签: vb.net textbox save format guitar


    【解决方案1】:

    下面的代码将所有文本框数据存储到一个字符串变量中,然后将该变量的内容分配给richtextbox。有两个按钮,一个用于将文本框数据发送到richtextbox,另一个用于将其保存到文本文件中。我希望你觉得它有用。

    公开课表1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
    
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim tbox As String = ""
        tbox &= TextBox1.Text & Environment.NewLine &
            TextBox2.Text & Environment.NewLine &
            TextBox3.Text & Environment.NewLine &
            TextBox4.Text & Environment.NewLine &
            TextBox5.Text
        RichTextBox1.Text = tbox
    End Sub
    
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        SaveMyFile()
    End Sub
    
    Public Sub SaveMyFile()
        ' Create a SaveFileDialog to request a path and file name to save to.
        Dim saveFile1 As New SaveFileDialog()
    
        ' Initialize the SaveFileDialog to specify the RTF extension for the file.
        saveFile1.DefaultExt = "*.txt"
        saveFile1.Filter = "TXT Files|*.txt"
    
        ' Determine if the user selected a file name from the saveFileDialog.
        If (saveFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
            And (saveFile1.FileName.Length) > 0 Then
    
            ' Save the contents of the RichTextBox into the file.
            RichTextBox1.SaveFile(saveFile1.FileName,
                RichTextBoxStreamType.PlainText)
        End If
    End Sub
    

    结束类

    【讨论】:

    • 感谢这帮了大忙!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    相关资源
    最近更新 更多