📄 printhpmobile.vb
字号:
encodeFile _
)
With brdrFile
Me.strName = .ReadString()
Me.sglSize = .ReadSingle()
Me.intStyle = .ReadInt32()
.Close()
End With
End Sub
End Structure
Private Sub SaveSettingsToFile()
' Create the directory and the file, if necessary.
If Not Directory.Exists(strDirName) Then _
Directory.CreateDirectory(strDirName)
Directory.SetCurrentDirectory(strDirName)
If Not File.Exists(strFileName) Then _
File.Create(strFileName).Close()
' Open a writer for the file
Dim bwrtFile As New BinaryWriter _
( _
New FileStream(strFileName, _
FileMode.OpenOrCreate, _
FileAccess.Write, _
FileShare.None), _
Me.encodeFile _
)
' Write the data to the file.
With bwrtFile
.Write(tboxInput.Font.Name) ' String.
.Write(tboxInput.Font.Size) ' Single.
.Write(tboxInput.Font.Style) ' Integer.
.Close()
End With
' Create an ourFontInfo structure, load it from
' tboxInput's font, have the structure save
' its contents to the file.
'Dim fiFont As ourFontInfo
'With tboxInput.Font
' fiFont.strName = .Name
' fiFont.sglSize = .Size
' fiFont.intStyle = .Style
'End With
'fiFont.WriteToFile(strDirName, _
' strFileName, _
' Encoding.Default)
End Sub
Private Sub ReadSettingsFromFile()
' Make the directory the current directory.
Directory.SetCurrentDirectory(strDirName)
' Open a reader for the file.
Dim brdrFile As New BinaryReader _
( _
New FileStream(strFileName, _
FileMode.OpenOrCreate, _
FileAccess.Read, _
FileShare.None), _
Me.encodeFile _
)
' Read each field from the file, then
' close the file.
With brdrFile
Dim strName As String = .ReadString()
Dim sglSize As Single = .ReadSingle()
Dim intStyle As Integer = .ReadInt32()
tboxInput.Font = _
New Font(strName, sglSize, intStyle)
.Close()
End With
End Sub
#End Region
#Region "Save/Restore to Registry"
' Utility object for registry access.
Dim urNotepad As New UtilRegistry
' Field names for the settings in the registry.
Dim strNotepadCE As String = "NotepadCe", _
strFont As String = "Font", _
strName As String = "Name", _
strSize As String = "Size", _
strStyle As String = "Style", _
strBold As String = "Bold", _
strItalic As String = "Italic", _
strUnderline As String = "Underline", _
strOptions As String = "Options", _
strMenu As String = "Menu", _
strToolBar As String = "ToolBar", _
strScrollBars As String = "ScrollBars", _
strTextAlign As String = "TextAlign", _
strWordWrap As String = "WordWrap"
Private Sub mitemSettingsSave_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) _
Handles mitemSettingsSave.Click
With tboxInput.Font
urNotepad.SetValue(strNotepadCE + "\" + strFont, _
strName, _
.Name)
urNotepad.SetValue(strNotepadCE + "\" + strFont, _
strSize, _
Convert.ToInt16(.Size))
urNotepad.SetValue(strNotepadCE + "\" + strFont, _
strStyle, _
Convert.ToInt16(.Style))
urNotepad.SetValue(strNotepadCE + "\" + strOptions, _
strMenu, _
Me.Menu Is Me.menuMain)
urNotepad.SetValue(strNotepadCE + "\" + strOptions, _
strToolBar, _
Me.Controls.Contains(tbarCommands))
urNotepad.SetValue(strNotepadCE + "\" + strOptions, _
strScrollBars, _
tboxInput.ScrollBars)
urNotepad.SetValue(strNotepadCE + "\" + strOptions, _
strTextAlign, _
tboxInput.TextAlign)
urNotepad.SetValue(strNotepadCE + "\" + strOptions, _
strWordWrap, _
tboxInput.WordWrap)
End With
End Sub
Private Sub mitemSettingsRestore_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) _
Handles mitemSettingsRestore.Click
' Read Font info, if any, from the registry,
' Create a font from that info, or use default
' values if no info is in the registry
' Set tboxInput.Font = that font
With urNotepad
Dim strFontName As String
Dim intFontSize As Integer
Dim intFontStyle As Integer
strFontName = "Tahoma"
.GetValue(strNotepadCE + "\" + strFont, _
strName, _
strFontName)
intFontSize = 9
.GetValue(strNotepadCE + "\" + strFont, _
strSize, _
intFontSize)
intFontStyle = FontStyle.Regular
.GetValue(strNotepadCE + "\" + strFont, _
strStyle, _
intFontStyle)
tboxInput.Font = _
New Font(strFontName, intFontSize, intFontStyle)
End With
' Read Option info, if any, from the registry
' Set the properties from that info, or use default
' values if no info is in the registry
Dim boolTemp As Boolean
Dim intTemp As Integer
With urNotepad
' .Menu is either menuMain or Nothing
boolTemp = True
.GetValue(strNotepadCE + "\" + strOptions, _
strMenu, _
boolTemp)
Me.Menu = IIf(boolTemp, Me.menuMain, Nothing)
' .Controls either contains
' tbarCommands or it doesn't
boolTemp = True
.GetValue(strNotepadCE + "\" + strOptions, _
strToolBar, _
boolTemp)
If boolTemp Then
If Not Me.Controls.Contains(Me.tbarCommands) Then
Me.Controls.Add(Me.tbarCommands)
End If
Else
If Me.Controls.Contains(Me.tbarCommands) Then
Me.Controls.Remove(Me.tbarCommands)
End If
End If
' .ScrollBars
intTemp = ScrollBars.Both
.GetValue(strNotepadCE + "\" + strOptions, _
strScrollBars, _
intTemp)
tboxInput.ScrollBars = intTemp
' .TextAlign
intTemp = HorizontalAlignment.Left
.GetValue(strNotepadCE + "\" + strOptions, _
strTextAlign, _
intTemp)
tboxInput.TextAlign = intTemp
' .WordWrap
boolTemp = True
.GetValue(strNotepadCE + "\" + strOptions, _
strWordWrap, _
boolTemp)
tboxInput.WordWrap = boolTemp
End With
End Sub
Private Sub mitemSettingsInit_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) _
Handles mitemSettingsInit.Click
urNotepad.DeleteKey(strNotepadCE)
mitemSettingsRestore_Click(Me, EventArgs.Empty)
End Sub
#End Region
#Region "Clipboard Support"
' Clipboard messages
Public Const WM_CUT = &H300
Public Const WM_COPY = &H301
Public Const WM_PASTE = &H302
Public Const WM_CLEAR = &H303
Public Const WM_UNDO = &H304
' Supports clipboard messages to text box.
Private m_msg As Microsoft.WindowsCE.Forms.Message
Private Sub mitemClipboard_Click( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles mitemCut.Click, mitemCopy.Click, _
mitemPaste.Click, mitemUndo.Click, mitemClear.Click
If sender.Equals(mitemCut) Then
m_msg.Msg = WM_CUT
' Cut does not work, so do equivalent...
m_msg.Msg = WM_COPY
MessageWindow.SendMessage(m_msg)
m_msg.Msg = WM_CLEAR
ElseIf sender.Equals(mitemCopy) Then
m_msg.Msg = WM_COPY
ElseIf sender.Equals(mitemPaste) Then
m_msg.Msg = WM_PASTE
ElseIf sender.Equals(mitemClear) Then
m_msg.Msg = WM_CLEAR
ElseIf sender.Equals(mitemUndo) Then
m_msg.Msg = WM_UNDO
End If
MessageWindow.SendMessage(m_msg)
End Sub
#End Region
#Region "Printing"
Dim hwndForm As IntPtr
Private Sub mitemFilePrint_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mitemFilePrint.Click
Dim hdcPrinter As IntPtr = IntPtr.Zero
Dim hfont As IntPtr = IntPtr.Zero
Dim hfontOld As IntPtr = IntPtr.Zero
Try
' Connect to printer by creating a DC.
hdcPrinter = mPrint.mPrintRenderWrapper.CreatePrinterContext()
If hdcPrinter.ToInt32() <> 0 Then
' Select font.
hfont = GdiFont.Create(tboxInput.Font.Name, _
CInt(tboxInput.Font.Size), 0, hdcPrinter)
hfontOld = GdiGraphics.SelectObject(hdcPrinter, hfont)
' Print
PrintJob_Gdi.PrintText(tboxInput, hdcPrinter)
Else
Throw New System.Exception
End If
Catch
MessageBox.Show("Error connecting to printer.", _
"PrintHPMobile")
Finally
' Cleanup
GdiGraphics.SelectObject(hdcPrinter, hfontOld)
GdiGraphics.DeleteObject(hfont)
mPrint.mPrintRenderWrapper.DeletePrinterContext(hdcPrinter)
End Try
End Sub
Private Sub FormMain_GotFocus( _
ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.GotFocus
hwndForm = WinFocus.GetFocus()
End Sub
#End Region
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -