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

📄 splashform.cs

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

namespace MobileDevelopersHandbook
{
    public partial class SplashForm : Form
    {
        public SplashForm()
        {
            InitializeComponent();
        }

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

        protected override void OnPaint(PaintEventArgs e)
        {
            using (Image backgroundImage =
                new Bitmap(System.Reflection.Assembly.GetExecutingAssembly()
                .GetManifestResourceStream("MobileDevelopersHandbook.Graphic.JPG")))
            {
                // Use the Graphics object from the PaintEventArgs
                //e.Graphics.DrawImage(backgroundImage, 0, 0);


                // Fill the background
                e.Graphics.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
                e.Graphics.DrawImage(backgroundImage, destRect, srcRect, GraphicsUnit.Pixel);
            }

            // Now draw text positioned inside a rectangle
            string s = "Mobile Developers Handbook";

            // Set default pen and font size
            int penSize = 4;
            int fontSize = 10;

            // Get dpi of current display
            float horResolution = e.Graphics.DpiX;
            if (horResolution > 100.0)
            {
                // Increase pen and font size on higher resolution devices
                penSize = 5;
                fontSize = 11;
            }

            using (Pen pen = new Pen(Color.Red, penSize))
            {
                using (Font font = new Font("Arial", fontSize, FontStyle.Regular))
                {
                    using (SolidBrush brush = new SolidBrush(Color.White))
                    {
                        SizeF textSize = e.Graphics.MeasureString(s, font);

                        // Create a rectangle with padding space between string and box
                        int rectWidth = Convert.ToInt32((textSize.Width) + 10);
                        int rectHeight = Convert.ToInt32((textSize.Height) + 10);
                        Rectangle r = new Rectangle(
                            (e.ClipRectangle.Width - rectWidth) / 2,
                            15, // 15 pixels from top of screen
                            rectWidth,
                            rectHeight);

                        e.Graphics.DrawRectangle(pen, r);
                        e.Graphics.DrawString(s, font, brush, r.Left + 5, r.Top + 5);

                        // Now draw a long string, but use a formatting rectangle and a StringFormat
                        // to wrap and align the text
                        string authors = "Authors: Andy Wigley, Daniel Moth, Peter Foot";

                        // Define the destination rectangle
                        RectangleF layoutRectangle = new RectangleF(15, this.Height - 50, this.Width - 20, 100);

                        // Create a StringFormat and set formating flags
                        StringFormat strFmt = new StringFormat();
                        strFmt.Alignment = StringAlignment.Center;
                        strFmt.FormatFlags = StringFormatFlags.NoClip;

                        // Draw the string
                        e.Graphics.DrawString(authors, font, brush, layoutRectangle, strFmt);
                   }
                }
            }


            // Draw a line with e.Graphics.DrawLine
            // Create pen.
            using (Pen redPen = new Pen(Color.Red, 3))
            {
                int length = e.ClipRectangle.Width - 20;
                int x1 = 10;
                int y1 = this.Height - 10;
                int x2 = length + 10;
                int y2 = y1;

                // Draw line to screen.
                e.Graphics.DrawLine(redPen, x1, y1, x2, y2);
            }

        }

    }
}

⌨️ 快捷键说明

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