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

📄 splashform.vb

📁 Windows mobile 图形编程例子
💻 VB
字号:
Imports System.IO
Imports System.Reflection
Imports Microsoft.WindowsCE.Forms

Public Class SplashForm

    Protected backBuffer As Bitmap

    Private Sub SplashForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Show full screen
        Me.ControlBox = False

    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        If Not backBuffer Is Nothing Then
            ' We need a Graphics object on the buffer to get an HDC
            Using gxBuffer As Graphics = Graphics.FromImage(backBuffer)

                Using backgroundImage As Image = _
                New Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MobileDevelopersHandbook.Graphic.JPG"))

                    ' Fill the background
                    gxBuffer.Clear(Color.Black)

                    ' Draw the image, but scale it
                    ' SourceRect is entire image
                    Dim srcRect As Rectangle = _
                            New Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height)
                    ' Define the destination rectangle size as 50% of the clipping rectangle
                    Dim destRect As Rectangle = _
                            New Rectangle(0, 0, e.ClipRectangle.Width / 2, e.ClipRectangle.Height / 2)
                    ' Reposition origin to centre the image on the screen
                    destRect.Location = New Point( _
                        (e.ClipRectangle.Width - destRect.Width) / 2, _
                        (e.ClipRectangle.Height - destRect.Height) / 2)

                    ' Draw the image
                    gxBuffer.DrawImage(backgroundImage, destRect, srcRect, GraphicsUnit.Pixel)
                End Using


                ' Create string to draw.
                Dim drawString As String = "Mobile Developers Handbook"

                ' Create font at 90 degrees.
                Using ft As Font = CreateLogFont(90)
                    Dim strSize As SizeF = e.Graphics.MeasureString(drawString, ft)

                    ' Create Rectangle just bigger than the size of the string
                    ' Note that in sizing this rectangle, we switch the height and width
                    ' returned by MeasureString, which doesn't take font angle into account
                    Dim areaWidth As Integer = CType(strSize.Height + 10, Integer)
                    Dim areaHeight As Integer = CType(strSize.Width + 10, Integer)

                    ' Fill into a bitmap and then draw that onto e.Graphics.
                    Using bm As Bitmap = New Bitmap(areaWidth, areaHeight)
                        Using gr As Graphics = System.Drawing.Graphics.FromImage(bm)
                            ' Fill the rectangular bitmap using gradient fill
                            GradientFill.Fill( _
                                gr, New Rectangle(0, 0, areaWidth, areaHeight), _
                                Color.Yellow, Color.Red, _
                                GradientFill.FillDirection.TopToBottom)

                            ' Draw the bitmap to the screen
                            gxBuffer.DrawImage(bm, 0, Me.Height - 15 - areaHeight)
                        End Using
                    End Using

                    ' Create brush.
                    Using drawBrush As SolidBrush = New SolidBrush(Color.DarkBlue)
                        ' Draw the string over the top
                        gxBuffer.DrawString(drawString, ft, drawBrush, 5, Me.Height - 20, New StringFormat(StringFormatFlags.NoClip Or StringFormatFlags.NoWrap))
                    End Using
                End Using

            End Using

            ' Put the final composed image on screen.
            e.Graphics.DrawImage(backBuffer, 0, 0)

        Else
            e.Graphics.Clear(Me.BackColor)
        End If
    End Sub

    Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
        ' Make this a no-op - background is painted in OnPaint
    End Sub

    Private Const POINTS_PER_INCH As Single = 72.0F

    Private Function CreateLogFont(ByVal angle As Integer) As Font
        ' Create and define a LogFont structure.
        Dim fontStruct As LogFont = New LogFont()

        Using g As Graphics = Me.CreateGraphics()
            ' Scale 10point for the dpi of the current display
            ' also make it negative, means match against character 
            ' height of available fonts
            fontStruct.Height = -1 * CType((12.0F * (g.DpiY / POINTS_PER_INCH)), Integer)
        End Using

        ' Since font width is usually dependent on the height, 
        ' usual to set width to zero
        fontStruct.Width = 0

        ' Set the font angle.
        ' Remember to multiply by 10.
        fontStruct.Escapement = angle * 10

        ' The Escapement member specifies both the
        ' escapement and orientation. You should set
        ' Escapement and Orientation to the same value.
        fontStruct.Orientation = fontStruct.Escapement

        ' No formatting.
        fontStruct.Italic = 0
        fontStruct.Underline = 0
        fontStruct.StrikeOut = 0
        ' Weight: 0 = default, 400 = normal, 700 = bold
        fontStruct.Weight = 0

        fontStruct.CharSet = LogFontCharSet.Default
        fontStruct.OutPrecision = LogFontPrecision.Default
        fontStruct.ClipPrecision = LogFontClipPrecision.Default
        fontStruct.Quality = LogFontQuality.Default
        fontStruct.PitchAndFamily = LogFontPitchAndFamily.Default

        fontStruct.FaceName = "Arial"

        ' Create the font from the LogFont structure.
        Return Font.FromLogFont(fontStruct)
    End Function

    Private Sub SplashForm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        If Not backBuffer Is Nothing Then
            ' dispose of the original one
            backBuffer.Dispose()
        End If

        ' Create a new backbuffer of the correct size
        backBuffer = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)

    End Sub
End Class

⌨️ 快捷键说明

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