?? form5.vb
字號:
Imports System.Drawing.Printing
Public Class Form5
Inherits System.Windows.Forms.Form
#Region " Windows 窗體設計器生成的代碼 "
Public Sub New()
MyBase.New()
'該調用是 Windows 窗體設計器所必需的。
InitializeComponent()
'在 InitializeComponent() 調用之后添加任何初始化
End Sub
'窗體重寫 dispose 以清理組件列表。
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
'Windows 窗體設計器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下過程是 Windows 窗體設計器所必需的
'可以使用 Windows 窗體設計器修改此過程。
'不要使用代碼編輯器修改它。
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents tblPrint As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
Friend WithEvents tblFont As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
Friend WithEvents tblColor As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton
Friend WithEvents RicPrint As System.Windows.Forms.RichTextBox
Friend WithEvents Printtext As System.Windows.Forms.PrintDialog
Friend WithEvents Font As System.Windows.Forms.FontDialog
Friend WithEvents Color As System.Windows.Forms.ColorDialog
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form5))
Me.RicPrint = New System.Windows.Forms.RichTextBox
Me.Printtext = New System.Windows.Forms.PrintDialog
Me.Font = New System.Windows.Forms.FontDialog
Me.Color = New System.Windows.Forms.ColorDialog
Me.ToolBar1 = New System.Windows.Forms.ToolBar
Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton
Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton
Me.tblPrint = New System.Windows.Forms.ToolBarButton
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
Me.tblFont = New System.Windows.Forms.ToolBarButton
Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton
Me.tblColor = New System.Windows.Forms.ToolBarButton
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.SuspendLayout()
'
'RicPrint
'
Me.RicPrint.Font = New System.Drawing.Font("隸書", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.RicPrint.HideSelection = False
Me.RicPrint.Location = New System.Drawing.Point(0, 32)
Me.RicPrint.Name = "RicPrint"
Me.RicPrint.Size = New System.Drawing.Size(528, 512)
Me.RicPrint.TabIndex = 0
Me.RicPrint.Text = "RichTextBox1"
'
'ToolBar1
'
Me.ToolBar1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.ToolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat
Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton3, Me.ToolBarButton4, Me.tblPrint, Me.ToolBarButton1, Me.tblFont, Me.ToolBarButton2, Me.tblColor})
Me.ToolBar1.ButtonSize = New System.Drawing.Size(51, 40)
Me.ToolBar1.Dock = System.Windows.Forms.DockStyle.None
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.Font = New System.Drawing.Font("宋體", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.ToolBar1.ImageList = Me.ImageList1
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(529, 28)
Me.ToolBar1.TabIndex = 1
Me.ToolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right
'
'ToolBarButton3
'
Me.ToolBarButton3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
'
'ToolBarButton4
'
Me.ToolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
'
'tblPrint
'
Me.tblPrint.ImageIndex = 1
Me.tblPrint.Text = "打印"
Me.tblPrint.ToolTipText = "打印信息"
'
'ToolBarButton1
'
Me.ToolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
'
'tblFont
'
Me.tblFont.ImageIndex = 2
Me.tblFont.Text = "字體"
Me.tblFont.ToolTipText = "設置字體"
'
'ToolBarButton2
'
Me.ToolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
'
'tblColor
'
Me.tblColor.ImageIndex = 3
Me.tblColor.Text = "顏色"
Me.tblColor.ToolTipText = "設置顏色"
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'Form5
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(528, 542)
Me.Controls.Add(Me.ToolBar1)
Me.Controls.Add(Me.RicPrint)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "Form5"
Me.Text = "Form5"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim filename As String = Application.StartupPath & "\print.tmp"
Try
RicPrint.Text = ""
RicPrint.LoadFile(filename, RichTextBoxStreamType.PlainText)
'RicPrint.Select
'ricprint.fo
Kill(filename)
Catch
'//
End Try
End Sub
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
Dim printdoc As New PrintDocument
Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 2
Try
AddHandler printdoc.PrintPage, AddressOf Me.print_text
printdoc.Print()
Catch ex As Exception
MessageBox.Show(ex.ToString, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Case 4
If Font.ShowDialog() = DialogResult.OK Then
RicPrint.SelectionFont = Font.Font
'//設定選中文本的字體
End If
Case 6
If Color.ShowDialog = DialogResult.OK Then
RicPrint.SelectionColor = Color.Color
'//設定選中文本的顏色
End If
End Select
End Sub
Private Sub print_text(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
ev.Graphics.DrawString(RicPrint.Text, New Font("隸書", 13, FontStyle.Regular), Brushes.Black, 120, 120)
'//指定打印樣式
ev.HasMorePages = False
'//指定這是最后一個打印頁
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -