⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 VB
字号:
Imports System.Drawing

Public Class Form1

    Private offscreenBuffer As Bitmap = Nothing

    Private Sub CloseMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseMenuItem.Click
        Settings.SaveSettings()
        Me.Close()
    End Sub

    Private Sub SettingsMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsMenuItem.Click
        Dim form As SettingsForm = New SettingsForm()
        form.ShowDialog()
        RepaintTextArea()
    End Sub

    Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        offscreenBuffer.Dispose()
        offscreenBuffer = Nothing
    End Sub

    Private Sub panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles panel1.Paint
        If offscreenBuffer Is Nothing Then
            UpdateOffscreenBuffer()
        End If
        ' Draw from background buffer to Panel
        e.Graphics.DrawImage(offscreenBuffer, 0, 0)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RepaintTextArea()
    End Sub

    Private Sub RepaintTextArea()
        UpdateOffscreenBuffer()
        Me.panel1.Invalidate()
    End Sub

    Private Sub UpdateOffscreenBuffer()
        ' Graphics settings
        Dim backgroundColor As Color = Settings.Instance.BackgroundColor
        Dim textColour As Color = Settings.Instance.TextColor
        Dim fontSize As Single = CType(Settings.Instance.FontSize, Single)
        Dim fontName As String = Settings.Instance.Fontname

        If offscreenBuffer Is Nothing Then
            offscreenBuffer = New Bitmap(Me.panel1.Width, Me.panel1.Height)
        End If

        ' Update the offscreen buffer.
        Using memDC As Graphics = Graphics.FromImage(offscreenBuffer)
            memDC.Clear(backgroundColor)
            Using boldFont As Font = New Font(fontName, fontSize, FontStyle.Bold)
                Using brsh As Brush = New SolidBrush(textColour)
                    memDC.DrawString("The style of this text", boldFont, brsh, 5, 5)
                    memDC.DrawString("is saved in Settings", boldFont, brsh, 5, 20)
                End Using
            End Using
        End Using
    End Sub


End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -