📄 printdirect.vb
字号:
#Region "Settings Menu Handlers"
' mitemEditFont - Respond to menu selection Edit->Font...
Private Sub mitemEditFont_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mitemEditFont.Click
Dim dlg As DlgFont = New DlgFont(Me)
' Initialize input values to dialog.
dlg.strFontName = tboxInput.Font.Name
dlg.cemFontSize = tboxInput.Font.Size
Dim fsTemp As FontStyle = tboxInput.Font.Style
dlg.bBold = ((fsTemp And FontStyle.Bold) <> 0)
dlg.bItalic = ((fsTemp And FontStyle.Italic) <> 0)
dlg.bUnderline = ((fsTemp And FontStyle.Underline) <> 0)
' Summon dialog box.
If (dlg.ShowDialog() <> DialogResult.OK) Then
Return
End If
' Modify settings based on user input.
Dim fontOld As Font = tboxInput.Font
fsTemp = 0
If (dlg.bBold) Then
fsTemp = fsTemp Or FontStyle.Bold
End If
If (dlg.bItalic) Then
fsTemp = fsTemp Or FontStyle.Italic
End If
If (dlg.bUnderline) Then
fsTemp = fsTemp Or FontStyle.Underline
End If
tboxInput.Font = New Font(dlg.strFontName, _
dlg.cemFontSize, fsTemp)
fontOld.Dispose()
End Sub
' mitemToolsOptions -- Respond to menu selection
' Tools->Options...
Private Sub mitemToolsOptions_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mitemToolsOptions.Click
Dim dlg As DlgToolsOptions = New DlgToolsOptions(Me)
' Get flag for whether toolbar is being displayed
Dim bHasTB As Boolean = Me.Controls.Contains(tbarCommands)
' Initialize input values to dialog.
dlg.sbScrollBars = tboxInput.ScrollBars
dlg.bProgramMenu = Not (Me.Menu Is Nothing)
dlg.bToolbar = bHasTB
dlg.haTextAlign = tboxInput.TextAlign
dlg.bWordWrap = tboxInput.WordWrap
' Summon dialog box.
If dlg.ShowDialog() <> DialogResult.OK Then
Return
End If
' Hide textbox to minimize redrawing time.
tboxInput.Visible = False
' Modify settings based on user input.
tboxInput.ScrollBars = dlg.sbScrollBars
Me.Menu = IIf((dlg.bProgramMenu), menuMain, Nothing)
' Do we need to add toolbar?
' (adding a toolbar twice causes an
' exception, so we have to be careful)
If dlg.bToolbar And (Not bHasTB) Then
Me.Controls.Add(tbarCommands)
End If
' Do we need to remove toolbar?
' (okay to remove a toolbar twice -- we
' do the following to parallel the add code)
If bHasTB And (Not dlg.bToolbar) Then
Me.Controls.Remove(tbarCommands)
End If
' Update text alignment.
tboxInput.TextAlign = dlg.haTextAlign
' Update word-wrap setting.
tboxInput.WordWrap = dlg.bWordWrap
' Make textbox visible again.
tboxInput.Visible = True
End Sub
' tbarCommands_ButtonClick - Respond to ButtonClick
' event for toolbar tbarCommands
Private Sub tbarCommands_ButtonClick( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) _
Handles tbarCommands.ButtonClick
If (e.Button Is tbbEditFormat) Then
mitemEditFont_Click(sender, e)
Else
mitemToolsOptions_Click(sender, e)
End If
End Sub
' cmenuMain_Popup -- Handle Popup event for
' context menu. Set/clear check-mark on context
' menu items.
Private Sub cmenuMain_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmenuMain.Popup
Dim bMenu As Boolean = Not (Me.Menu Is Nothing)
mitemProgramMenu.Checked = bMenu
Dim bTB As Boolean = Me.Controls.Contains(tbarCommands)
mitemToolbar.Checked = bTB
End Sub
Private Sub mitemProgramMenu_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mitemProgramMenu.Click
If (Me.Menu Is Nothing) Then
Me.Menu = menuMain
Else
Me.Menu = Nothing
End If
End Sub
Private Sub mitemToolbar_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mitemToolbar.Click
If (mitemToolbar.Checked) Then
Me.Controls.Remove(tbarCommands)
Else
Me.Controls.Add(tbarCommands)
End If
End Sub
#End Region
#Region "Text FileIO routines"
Private fdlgOpen As OpenFileDialog
Private fdlgSave As SaveFileDialog
Private encodeFile As Text.Encoding = Encoding.Default
Private strCurrentFile As String = String.Empty
Private Sub mitemFileOpen_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) _
Handles mitemFileOpen.Click
' Create a OpenFile dialog if necessary.
If fdlgOpen Is Nothing Then _
fdlgOpen = New OpenFileDialog
fdlgOpen.InitialDirectory = "NotepadCE"
fdlgOpen.Filter = "dat files (*.dat)|*.dat|" & _
"txt files (*.txt)|*.txt|" & _
"All files (*.*)|*.*"
' Show it.
Select Case fdlgOpen.ShowDialog()
' Check user's response.
Case DialogResult.OK
' Save file name.
strCurrentFile = fdlgOpen.FileName
' Open, read, close file.
Dim srdrFile As New StreamReader _
( _
New FileStream(strCurrentFile, _
FileMode.Open), _
Me.encodeFile _
)
With srdrFile
Me.tboxInput.Text = .ReadToEnd()
.Close()
End With
Case Else
End Select
End Sub
Private Sub mitemFileSave_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) _
Handles mitemFileSave.Click
' If the user has not yet specified
' a file name, do SaveAs.
' Else,
' open, write, close file.
If strCurrentFile = String.Empty Then
mitemFileSaveAs_Click(sender, e)
Else
Dim swrtFile As New StreamWriter _
( _
New FileStream(strCurrentFile, _
FileMode.Truncate), _
Me.encodeFile _
)
With swrtFile
.Write(Me.tboxInput.Text)
.Close()
End With
End If
End Sub
Private Sub mitemFileSaveAs_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) _
Handles mitemFileSaveAs.Click
' Get the file name from the user.
If fdlgSave Is Nothing Then _
fdlgSave = New SaveFileDialog
Select Case fdlgSave.ShowDialog()
Case DialogResult.OK
' Save file name.
strCurrentFile = fdlgSave.FileName
' Save file.
mitemFileSave_Click(sender, e)
Case Else
End Select
End Sub
Private Sub mitemFileFormat_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) _
Handles mitemFFAscii.Click, _
mitemFFDefault.Click, _
mitemFFUnicode.Click, _
mitemFFUtf7.Click, _
mitemFFUtf8.Click
If sender.Equals(mitemFFAscii) Then
Me.encodeFile = Encoding.ASCII
ElseIf sender.Equals(mitemFFUnicode) Then
Me.encodeFile = Encoding.Unicode
ElseIf sender.Equals(mitemFFUtf7) Then
Me.encodeFile = Encoding.UTF7
ElseIf sender.Equals(mitemFFUtf8) Then
Me.encodeFile = Encoding.UTF8
Else
Me.encodeFile = Encoding.Default
End If
End Sub
#End Region
#Region "Binary File IO routines"
Private strDirName As String = _
"My Documents\YaoDurant\NotepadCE"
Private strFileName As String = _
"Settings.dat"
' A structure containing font information and
' routines to dump and restore that info
' to / from a file.
Private Structure ourFontInfo
Public strName As String
Public sglSize As Single
Public intStyle As Integer
Public Sub New(ByVal strName As String, _
ByVal sglSize As Single, _
ByVal intStyle As Integer)
Me.strName = strName
Me.sglSize = sglSize
Me.intStyle = intStyle
End Sub
Public Sub WriteToFile(ByVal strDirName As String, _
ByVal strFileName As String, _
ByVal encodeFile As Encoding)
If Not Directory.Exists(strDirName) Then _
Directory.CreateDirectory(strDirName)
Directory.SetCurrentDirectory(strDirName)
If Not File.Exists(strFileName) Then _
File.Create(strFileName).Close()
Dim bwrtFile As New BinaryWriter _
( _
New FileStream(strFileName, _
FileMode.OpenOrCreate, _
FileAccess.Write, _
FileShare.None), _
encodeFile _
)
With bwrtFile
.Write(Me.strName)
.Write(Me.sglSize)
.Write(Me.intStyle)
.Close()
End With
End Sub
Public Sub ReadFromFile(ByVal strDirName As String, _
ByVal strFileName As String, _
ByVal encodeFile As Encoding)
Directory.SetCurrentDirectory(strDirName)
Dim brdrFile As New BinaryReader _
( _
New FileStream(strFileName, _
FileMode.OpenOrCreate, _
FileAccess.Read, _
FileShare.None), _
encodeFile _
)
With brdrFile
Me.strName = .ReadString()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -