?? 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;
Font captionFont;
string time = "";
Graphics gxBuffer;
Bitmap offBitmap;
string date = "";
string caption = "China Mobile";
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");
//slideAni = new Bitmap(path + @"\BMP\SignalLevelMedium.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", 10, FontStyle.Regular);
dateFont = new Font("Tahoma", 9, FontStyle.Regular);
captionFont=new Font("Tahoma", 22, 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();
//caption = new string("China Mobile");
offBitmap = new Bitmap(this.Width, this.Height);
_iPhoneMainMenu = new MainMenu();
timerSlideAnimation.Enabled = true;//
timerSlideAnimation.Interval = 2;
// ShowTaskBar(false);
}
/*public static void ShowTaskBar(bool bShow)//
{
{
IntPtr h = PlatformAPIs.FindWindowW("HHTaskBar", "");
PlatformAPIs.ShowWindow(h, bShow? (int)PlatformAPIs.ShowWindowFlags.SW_SHOW:(int)PlatformAPIs.ShowWindowFlags.SW_HIDE);
PlatformAPIs.EnableWindow(h, false);
}
}*/
private void Form1_ParentChanged(object sender, EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)
//貌似把所有的圖案都繪到內存里了
{
if (arrowButton.unLock)//如果解鎖,則顯示主菜單界面
{
arrowButton.unLock = false;
_iPhoneMainMenu.ShowDialog();
arrowButton.ResetPosition();
}
{
//首先要知道所有圖像都是向Graphics上面繪制
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 +4);
DrawCaption(caption, gxBuffer, topLock.Height + 12);
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();//觸發paint事件
arrowButton.Paint(gxBuffer);
e.Graphics.DrawImage(offBitmap, 0, 0);
}
if (_iPhoneMainMenu.CloseApp)
Close();
}
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;
int x = this.Width - (int)size.Width - 2; //加入size之后實現位置隨字體改變
gx.DrawString(time, timeFont, new SolidBrush(Color.White), x, y);
}
private void DrawCaption(string caption, Graphics gx, int y)
{
SizeF size = gx.MeasureString(caption, captionFont);
//int x = this.Width / 2 - (int)size.Width / 2;
int x = this.Width/2 - (int)size.Width/2;
gx.DrawString(caption, captionFont, new SolidBrush(Color.White), x, y);
}
//調用: DrawAlpha(gxBuffer, topBar, 170, 0, topLock.Height);
/* 本函數是該程序的核心,trans透明度,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;
}
//call : DrawAlphaAnimation(gxBuffer, slideAni, 160, 0, 258);
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);
//x-frame與滾動高亮顯示相關
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)
{
}
private void Home_Closing(object sender, CancelEventArgs e)
{
// ShowTaskBar(true);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -