在使用VB的RichTextBox控件时加载文档(RTF)出现错误,应用程序出错,不能写入。
1个回答
展开全部
下面的代码示例将一个 RTF 文件打开到 RichTextBox 控件中。本示例使用 OpenFileDialog 类显示一个从用户请求文件的对话框。如果文件为 RTF 文档文件,则代码接着加载此文件。如果此文件不是 RTF 文档文件,则代码示例将引发异常。此示例要求将代码放置在包含一个名为
richTextBox1 的 RichTextBox 控件的 Form 类中。
Public Sub LoadMyFile()
' Create an OpenFileDialog to request a file to open.
Dim openFile1 As New OpenFileDialog()
' Initialize the OpenFileDialog to look for RTF files.
openFile1.DefaultExt = "*.rtf"
openFile1.Filter = "RTF Files|*.rtf"
' Determine whether the user selected a file from the OpenFileDialog.
If (openFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
And (openFile1.FileName.Length > 0) Then
' Load the contents of the file into the RichTextBox.
richTextBox1.LoadFile(openFile1.FileName)
End If
End Sub
richTextBox1 的 RichTextBox 控件的 Form 类中。
Public Sub LoadMyFile()
' Create an OpenFileDialog to request a file to open.
Dim openFile1 As New OpenFileDialog()
' Initialize the OpenFileDialog to look for RTF files.
openFile1.DefaultExt = "*.rtf"
openFile1.Filter = "RTF Files|*.rtf"
' Determine whether the user selected a file from the OpenFileDialog.
If (openFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
And (openFile1.FileName.Length > 0) Then
' Load the contents of the file into the RichTextBox.
richTextBox1.LoadFile(openFile1.FileName)
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询