本文整理汇总了VB.NET中System.Windows.Forms.RichTextBox.LoadFile方法的典型用法代码示例。如果您正苦于以下问题:VB.NET RichTextBox.LoadFile方法的具体用法?VB.NET RichTextBox.LoadFile怎么用?VB.NET RichTextBox.LoadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.LoadFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: LoadMyFile
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
示例2: New
' 导入命名空间
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms
Partial Public Class Form1
Inherits Form
Friend WithEvents RichTextBox1 As RichTextBox
Friend WithEvents Button1 As Button
Friend WithEvents RichTextBox2 As RichTextBox
Friend WithEvents Button2 As Button
Friend WithEvents SaveFileDialog1 As SaveFileDialog
Public Sub New()
MyBase.New()
Me.RichTextBox1 = New RichTextBox
Me.Button1 = New Button
Me.RichTextBox2 = New RichTextBox
Me.Button2 = New Button
Me.SaveFileDialog1 = New SaveFileDialog
Me.SuspendLayout()
Me.RichTextBox1.Location = New Point(24, 64)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "Type something here."
Me.Button1.Location = New Point(96, 16)
Me.Button1.Name = "Button1"
Me.Button1.Size = New Size(96, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Save To Stream"
Me.RichTextBox2.Location = New Point(152, 64)
Me.RichTextBox2.Name = "RichTextBox2"
Me.RichTextBox2.TabIndex = 3
Me.RichTextBox2.Text = "It will be added to the stream and appear here."
Me.Button2.Location = New Point(104, 200)
Me.Button2.Name = "Button2"
Me.Button2.Size = New Size(88, 32)
Me.Button2.TabIndex = 4
Me.Button2.Text = "Save Stream To File"
Me.ClientSize = New Size(292, 266)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.RichTextBox2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
Public Shared Sub Main()
Application.Run(New Form1)
End Sub
' Declare a new memory stream.
Dim userInput As New MemoryStream
' Save the content of RichTextBox1 to the memory stream, appending
'a LineFeed character.
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button1.Click
RichTextBox1.SaveFile(userInput, RichTextBoxStreamType.PlainText)
userInput.WriteByte(13)
' Display the entire contents of the stream,
' by setting its position to 0, to RichTextBox2.
userInput.Position = 0
RichTextBox2.LoadFile(userInput, RichTextBoxStreamType.PlainText)
End Sub
' Shows the use of a SaveFileDialog to save a MemoryStream to a file.
Private Sub Button2_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button2.Click
' Set the properties on SaveFileDialog1 so the user is
' prompted to create the file if it doesn't exist
' or overwrite the file if it does exist.
SaveFileDialog1.CreatePrompt = True
SaveFileDialog1.OverwritePrompt = True
' Set the file name to myText.txt, set the type filter
' to text files, and set the initial directory to the
' MyDocuments folder.
SaveFileDialog1.FileName = "myText"
' DefaultExt is only used when "All files" is selected from
' the filter box and no extension is specified by the user.
SaveFileDialog1.DefaultExt = "txt"
SaveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
SaveFileDialog1.InitialDirectory = _
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
' Call ShowDialog and check for a return value of DialogResult.OK,
' which indicates that the file was saved.
Dim result As DialogResult = SaveFileDialog1.ShowDialog()
Dim fileStream As Stream
If (result = DialogResult.OK) Then
' Open the file, copy the contents of memoryStream to fileStream,
' and close fileStream. Set the memoryStream.Position value to 0 to
' copy the entire stream.
fileStream = SaveFileDialog1.OpenFile()
userInput.Position = 0
userInput.WriteTo(fileStream)
fileStream.Close()
End If
End Sub
End Class
示例3: LoadMyFile
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, _
RichTextBoxStreamType.PlainText)
End If
End Sub
示例4: MainClass
' 导入命名空间
Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Printing
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(292, 269)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.ClientSize = New System.Drawing.Size(292, 269)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.RichTextBox1})
Me.Name = "Form1"
Me.Text = "Example"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RichTextBox1.LoadFile("test.vb", RichTextBoxStreamType.PlainText)
End Sub
End Class