📄 home.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Microsoft.WindowsMobile.Status;
namespace iPhoneUI
{
public partial class Home : Form
{
string path = "";
Bitmap backImage;
Bitmap topBar;
Bitmap topLock;
Bitmap batteryLevelMedium ;
Bitmap batteryLevelLow ;
Bitmap batteryLevelVeryLow1;
Bitmap batteryLevelVeryLow2;
Bitmap batteryLevelVeryHigh;
Bitmap batteryLevelHigh;
Bitmap signalLevelVeryHigh;
Bitmap signalLevelHigh;
Bitmap signalLevelMedium;
Bitmap signalLevelLow;
Bitmap signalLevelVerylow1;
Bitmap signalLevelVerylow2;
Bitmap slideAni;
Font timeFont;
Font dateFont;
string time = "";
Graphics gxBuffer;
Bitmap offBitmap;
string date = "";
Brush whiteBrush;
bool _HideBattery = false;
bool _HideSignal = false;
private SlideButton arrowButton;
int LastXAnimation = 0;
MainMenu _iPhoneMainMenu;
public Home()
{
InitializeComponent();
path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
backImage = new Bitmap(path + @"\BMP\wallpaper.bmp");
topBar = new Bitmap(path + @"\BMP\topbar.bmp");
topLock = new Bitmap(path + @"\BMP\toplock.bmp");
batteryLevelVeryHigh = new Bitmap(path + @"\BMP\BatteryLevelVeryHigh.bmp");
batteryLevelHigh = new Bitmap(path + @"\BMP\BatteryLevelHigh.bmp");
batteryLevelMedium = new Bitmap(path + @"\BMP\BatteryLevelMedium.bmp");
batteryLevelLow = new Bitmap(path + @"\BMP\BatteryLevelLow.bmp");
batteryLevelVeryLow1 = new Bitmap(path + @"\BMP\BatteryLevelVeryLow1.bmp");
batteryLevelVeryLow2 = new Bitmap(path + @"\BMP\BatteryLevelVeryLow2.bmp");
signalLevelVeryHigh = new Bitmap(path + @"\BMP\SignalLevelVeryHigh.bmp");
signalLevelHigh = new Bitmap(path + @"\BMP\SignalLevelHigh.bmp");
signalLevelMedium = new Bitmap(path + @"\BMP\SignalLevelMedium.bmp");
signalLevelLow = new Bitmap(path + @"\BMP\SignalLevelLow.bmp");
signalLevelVerylow1 = new Bitmap(path + @"\BMP\SignalLevelVeryLow1.bmp");
signalLevelVerylow2 = new Bitmap(path + @"\BMP\SignalLevelVeryLow2.bmp");
slideAni = new Bitmap(path + @"\BMP\slideAni.bmp");
arrowButton = new SlideButton(this, new Point(16, 274));
arrowButton.Image = new Bitmap(path + @"\BMP\arrow.bmp");
arrowButton.ImageDown = new Bitmap(path + @"\BMP\arrowDown.bmp");
timeFont = new Font("Tahoma", 32, FontStyle.Regular);
dateFont = new Font("Tahoma", 9, FontStyle.Regular);
whiteBrush = new SolidBrush(Color.White);
time = DateTime.Now.ToString("hh:mm");
date = DateTime.Now.DayOfWeek.ToString() + ", " + DateTime.Now.ToString("MMMM") + " " + DateTime.Now.Day.ToString();
offBitmap = new Bitmap(this.Width, this.Height);
_iPhoneMainMenu = new MainMenu();
timerSlideAnimation.Enabled = true;
timerSlideAnimation.Interval = 2;
}
private void Form1_ParentChanged(object sender, EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)
{
if (arrowButton.unLock)
{
arrowButton.unLock = false;
_iPhoneMainMenu.ShowDialog();
arrowButton.ResetPosition();
}
{
gxBuffer = Graphics.FromImage(offBitmap);
//Graphics gxBuffer = e.Graphics;
gxBuffer.Clear(this.BackColor);
//Draw background first
gxBuffer.DrawImage(backImage, 0, 0);
DrawTop(ref gxBuffer);
DrawAlpha(gxBuffer, topBar, 170, 0, topLock.Height);
time = DateTime.Now.ToString("hh:mm");
DrawTime(time, gxBuffer, topLock.Height + 2);
SizeF size = gxBuffer.MeasureString(date, dateFont);
int x = this.Width / 2 - (int)size.Width / 2;
gxBuffer.DrawString(date, dateFont, whiteBrush, x, 70);
DrawAlphaAnimation(gxBuffer, slideAni, 160, 0, 258);
this.Invalidate();
arrowButton.Paint(gxBuffer);
e.Graphics.DrawImage(offBitmap, 0, 0);
}
}
private void DrawTop(ref Graphics gxBuffer)
{
//this.Invalidate(new Rectangle(0, 0, topLock.Width + signal.Width + batteryLevelHigh.Width, topLock.Height));
//DrawAlpha(gxBuffer, signalLevelVeryHigh, 200, 0, 0);
DrawAlpha(gxBuffer, GetGPSSignalImage(), 200, 0, 0);
DrawAlpha(gxBuffer, topLock, 200, signalLevelVeryHigh.Width, 0);
DrawAlpha(gxBuffer, GetBatteryImage(), 200, topLock.Width + signalLevelVeryHigh.Width, 0);
}
private Bitmap GetBatteryImage()
{
switch (SystemState.PowerBatteryStrength)
{
case BatteryLevel.VeryHigh:
return batteryLevelVeryHigh;
case BatteryLevel.High:
return batteryLevelHigh;
case BatteryLevel.Medium:
return batteryLevelMedium;
case BatteryLevel.Low:
return batteryLevelLow;
case BatteryLevel.VeryLow:
_HideBattery = !_HideBattery;
if (_HideBattery)
return batteryLevelVeryLow1;
else
return batteryLevelVeryLow2;
}
return null;
}
private Bitmap GetGPSSignalImage()
{
int SignalStrength = SystemState.PhoneSignalStrength;
if (SignalStrength > 80)
return signalLevelVeryHigh;
if (SignalStrength > 60)
return signalLevelHigh;
if (SignalStrength > 50)
return signalLevelMedium;
if (SignalStrength > 20)
return signalLevelLow;
//else
{
_HideSignal = !_HideSignal;
if (_HideSignal)
return signalLevelVerylow1;
else
return signalLevelVerylow2;
}
return null;
}
protected override void OnPaintBackground(PaintEventArgs e)
{
//base.OnPaintBackground(e);
}
private void DrawTime(string time, Graphics gx, int y)
{
SizeF size = gx.MeasureString(time, timeFont);
int x = this.Width / 2 - (int)size.Width / 2;
gx.DrawString(time, timeFont, new SolidBrush(Color.White), x, y);
}
private void DrawAlpha(Graphics gx, Bitmap image, byte transp, int x, int y)
{
using (Graphics gxSrc = Graphics.FromImage(image))
{
IntPtr hdcDst = gx.GetHdc();
IntPtr hdcSrc = gxSrc.GetHdc();
BlendFunction blendFunction = new BlendFunction();
blendFunction.BlendOp = (byte)BlendOperation.AC_SRC_OVER; // Only supported blend operation
blendFunction.BlendFlags = (byte)BlendFlags.Zero; // Documentation says put 0 here
blendFunction.SourceConstantAlpha = transp;// Constant alpha factor
blendFunction.AlphaFormat = (byte)0; // Don't look for per pixel alpha
PlatformAPIs.AlphaBlend(hdcDst, x, y, image.Width, image.Height, hdcSrc, 0, 0, image.Width, image.Height, blendFunction);
gx.ReleaseHdc(hdcDst); // Required cleanup to GetHdc()
gxSrc.ReleaseHdc(hdcSrc); // Required cleanup to GetHdc()
}
}
private void DrawAlphaAnimation(Graphics gx, Bitmap image, byte transp, int x, int y)
{
LastXAnimation = LastXAnimation + 240;
if (LastXAnimation >= slideAni.Width)
{
LastXAnimation = 0;
}
int frame = LastXAnimation;
using (Graphics gxSrc = Graphics.FromImage(image))
{
//this.Invalidate(new Rectangle(0, 258, slideAni.Width, slideAni.Height));
IntPtr hdcDst = gx.GetHdc();
IntPtr hdcSrc = gxSrc.GetHdc();
BlendFunction blendFunction = new BlendFunction();
blendFunction.BlendOp = (byte)BlendOperation.AC_SRC_OVER; // Only supported blend operation
blendFunction.BlendFlags = (byte)BlendFlags.Zero; // Documentation says put 0 here
blendFunction.SourceConstantAlpha = transp;// Constant alpha factor
blendFunction.AlphaFormat = (byte)0; // Don't look for per pixel alpha
// PlatformAPIs.AlphaBlend(hdcDst, x, y, image.Width, image.Height, hdcSrc, 0, y + frame, image.Width, image.Height, blendFunction);
PlatformAPIs.AlphaBlend(hdcDst, x - frame, y, image.Width, image.Height, hdcSrc, 0, 0, image.Width, image.Height, blendFunction);
gx.ReleaseHdc(hdcDst); // Required cleanup to GetHdc()
gxSrc.ReleaseHdc(hdcSrc); // Required cleanup to GetHdc()
}
}
private void hScrollBar_ValueChanged(object sender, EventArgs e)
{
this.Invalidate();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Home_Activated(object sender, EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -