📄 splashform.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
{
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")))
{
// Fill the background
e.Graphics.Clear(Color.Red);
// The .NET Compact Framework supports transparency but with
// only one transparency color.
// The SetColorKey method must have the same color specified
// for the low color and high color range.
System.Drawing.Imaging.ImageAttributes attr =
new System.Drawing.Imaging.ImageAttributes();
// Sets the transparency color key based on the upper left pixel of the image
attr.SetColorKey(((Bitmap)backgroundImage).GetPixel(0, 0),
((Bitmap)backgroundImage).GetPixel(0, 0));
// Draw the image, but scale it to 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 using the image attributes.
e.Graphics.DrawImage(backgroundImage, destRect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, attr);
}
// 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
e.Graphics.DrawImage(bm, 0, this.Height - 15 - areaHeight);
}
}
// Create brush.
using (SolidBrush drawBrush = new SolidBrush(Color.DarkBlue))
{
// Draw the string over the top
e.Graphics.DrawString(drawString,
ft,
drawBrush,
5,
this.Height - 20,
new StringFormat(StringFormatFlags.NoClip | StringFormatFlags.NoWrap));
}
}
base.OnPaint(e);
}
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);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -