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

📄 splashform.cs

📁 Windows mobile 图形编程例子
💻 CS
字号:
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace MobileDevelopersHandbook
{
    public partial class SplashForm : Form
    {
        protected Bitmap backBuffer;

        public SplashForm()
        {
            InitializeComponent();
        }

        private void SplashForm_Load(object sender, EventArgs e)
        {
            // Show full screen
            this.ControlBox = false;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (backBuffer != null)
            {
                // We need a Graphics object on the buffer to get an HDC
                using (Graphics gxBuffer = Graphics.FromImage(backBuffer))
                {
                    using (Image backgroundImage =
                        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
                        Rectangle srcRect =
                            new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height);
                        // Define the destination rectangle size as 50% of the clipping rectangle
                        Rectangle destRect =
                            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);
                    }

                    // Create string to draw.
                    string drawString = "Mobile Developers Handbook";

                    // Create font at 90 degrees.
                    using (Font ft = CreateLogFont(90))
                    {
                        SizeF strSize = 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
                        int areaWidth = (int)strSize.Height + 10;
                        int areaHeight = (int)strSize.Width + 10;

                        // Fill into a bitmap and then draw that onto e.Graphics.
                        using (Bitmap bm = new Bitmap(areaWidth, areaHeight))
                        {
                            using (Graphics gr = 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, this.Height - 15 - areaHeight);
                            }
                        }

                        // Create brush.
                        using (SolidBrush drawBrush = new SolidBrush(Color.DarkBlue))
                        {
                            // Draw the string over the top
                            gxBuffer.DrawString(drawString,
                                                ft,
                                                drawBrush,
                                                5,
                                                this.Height - 20,
                                                new StringFormat(StringFormatFlags.NoClip | StringFormatFlags.NoWrap));
                        }
                    }
                }

                // Put the final composed image on screen.
                e.Graphics.DrawImage(backBuffer, 0, 0);
            }
            else
                e.Graphics.Clear(this.BackColor);
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            // Make this a no-op - background is painted in OnPaint
        }

        private Font CreateLogFont(int angle)
        {
            // Create and define a LogFont structure.
            LogFont fontStruct = new LogFont();

            // Scale 12pt font size (at 96dpi) for the  dpi of the current display
            using (Graphics g = this.CreateGraphics())
            {
                // Scale 12point for the dpi of the current display
                // also make it negative, means match against character 
                // height of available fonts
                fontStruct.Height = -1 * (int)(12f * (g.DpiY / 72.0));
            }

            // 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);
        }

        private void SplashForm_Resize(object sender, EventArgs e)
        {
            if (backBuffer != null)
            {
                // dispose of the original one
                backBuffer.Dispose();
            }

            // Create a new backbuffer of the correct size
            backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
        }
    }
}

⌨️ 快捷键说明

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