📄 mainmenu.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 System.Runtime.InteropServices;
using System.IO;
namespace iPhoneUI
{
public partial class MainMenu : Form
{
bool bShowTaskMgr = false;
Bitmap backImageMainMenu;
Graphics gxBuffer;
Bitmap offBitmap;
string path;
private ImageButton buttonPhone;
private ImageButton buttonSMS;
private ImageButton buttonCalendar;
private ImageButton buttonPhoto;
private ImageButton buttonCamera;
private ImageButton buttonCalculator;
private ImageButton buttonInternetExplorer;
private ImageButton buttonLock;
private ImageButton buttonNotes;
private ImageButton buttonSettings;
private ImageButton buttonMail;
private ImageButton buttonMediaPlayer;
private ImageButton buttonTaskManager;
private ImageButton buttonIBM;
private ImageButton buttonClose;
public bool CloseApp = false;
bool NeedRepaint = false;
private InterceptButtonPressed InterceptButton = new InterceptButtonPressed();
public MainMenu()
{
InitializeComponent();
//OperatingSystem op = System.Environment.OSVersion;
FindTaskManger();
timerCheckButtonPressed.Enabled = true;
int iStart = 15;
int iStep = 55;
int iStepY = 65;
Point[] ButtonGridPosition = { new Point(iStart, iStart),
new Point(iStart+iStep,iStart+iStepY),
new Point(iStart+iStep*2,iStart+iStepY*2),
new Point(iStart+iStep*3,iStepY*4),
}; //定了四个点,貌似是一条斜线,给平面上的布局提供坐标
offBitmap = new Bitmap(this.Width, this.Height);
gxBuffer = Graphics.FromImage(offBitmap);
path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
backImageMainMenu = new Bitmap(path + @"\BMP\IBMbackground.bmp");
//1
buttonSMS = new ImageButton(this, new Point(ButtonGridPosition[0].X, ButtonGridPosition[0].Y));
buttonSMS.Image = new Bitmap(path + @"\BMP\Chat 46x46.bmp");
buttonSMS.ImageDown = new Bitmap(path + @"\BMP\Chat 46x46_pressed.bmp");
buttonCalendar = new ImageButton(this, new Point(ButtonGridPosition[1].X, ButtonGridPosition[0].Y));
buttonCalendar.Image = new Bitmap(path + @"\BMP\Calendar_46x46.bmp");
buttonCalendar.ImageDown = new Bitmap(path + @"\BMP\Calendar_46x46_pressed.bmp");
buttonPhoto = new ImageButton(this, new Point(ButtonGridPosition[2].X, ButtonGridPosition[0].Y));
buttonPhoto.Image = new Bitmap(path + @"\BMP\Photo 46x46.bmp");
buttonPhoto.ImageDown = new Bitmap(path + @"\BMP\Photo 46x46_pressed.bmp");
buttonCamera = new ImageButton(this, new Point(ButtonGridPosition[3].X, ButtonGridPosition[0].Y));
buttonCamera.Image = new Bitmap(path + @"\BMP\Camera 46x46.bmp");
buttonCamera.ImageDown = new Bitmap(path + @"\BMP\Camera 46x46_pressed.bmp");
//2
buttonCalculator = new ImageButton(this, new Point(ButtonGridPosition[0].X, ButtonGridPosition[1].Y));
buttonCalculator.Image = new Bitmap(path + @"\BMP\Calculator 46x46.bmp");
buttonCalculator.ImageDown = new Bitmap(path + @"\BMP\Calculator 46x46_pressed.bmp");
buttonMediaPlayer = new ImageButton(this, new Point(ButtonGridPosition[1].X, ButtonGridPosition[1].Y));
buttonMediaPlayer.Image = new Bitmap(path + @"\BMP\Windows Media Player 46x46.bmp");
buttonMediaPlayer.ImageDown = new Bitmap(path + @"\BMP\Windows Media Player 46x46_pressed.bmp");
buttonInternetExplorer = new ImageButton(this, new Point(ButtonGridPosition[2].X, ButtonGridPosition[1].Y));
buttonInternetExplorer.Image = new Bitmap(path + @"\BMP\Internet Explorer 46x46.bmp");
buttonInternetExplorer.ImageDown = new Bitmap(path + @"\BMP\Internet Explorer 46x46_pressed.bmp");
buttonNotes = new ImageButton(this, new Point(ButtonGridPosition[3].X, ButtonGridPosition[1].Y));
buttonNotes.Image = new Bitmap(path + @"\BMP\Notes 46x46.bmp");
buttonNotes.ImageDown = new Bitmap(path + @"\BMP\Notes 46x46_pressed.bmp");
//3
buttonSettings = new ImageButton(this, new Point(ButtonGridPosition[0].X, ButtonGridPosition[2].Y));
buttonSettings.Image = new Bitmap(path + @"\BMP\Settings 46x46.bmp");
buttonSettings.ImageDown = new Bitmap(path + @"\BMP\Settings 46x46_pressed.bmp");
if (bShowTaskMgr)
{
buttonTaskManager = new ImageButton(this, new Point(ButtonGridPosition[1].X, ButtonGridPosition[2].Y));
buttonTaskManager.Image = new Bitmap(path + @"\BMP\TaskManager 46x46.bmp");
buttonTaskManager.ImageDown = new Bitmap(path + @"\BMP\TaskManager 46x46_pressed.bmp");
}
buttonClose = new ImageButton(this, new Point(ButtonGridPosition[3].X, ButtonGridPosition[2].Y));
buttonClose.Image = new Bitmap(path + @"\BMP\Close 46x46.bmp");
buttonClose.ImageDown = new Bitmap(path + @"\BMP\Close 46x46_pressed.bmp");
//4
buttonPhone = new ImageButton(this, new Point(ButtonGridPosition[0].X, ButtonGridPosition[3].Y+6));
buttonPhone.Image = new Bitmap(path + @"\BMP\Phone 46x46.bmp");
buttonPhone.ImageDown = new Bitmap(path + @"\BMP\Phone 46x46_pressed.bmp");
buttonMail = new ImageButton(this, new Point(ButtonGridPosition[1].X, ButtonGridPosition[3].Y+6));
buttonMail.Image = new Bitmap(path + @"\BMP\Mail 46x46.bmp");
buttonMail.ImageDown = new Bitmap(path + @"\BMP\Mail 46x46_pressed.bmp");
/*buttonIBM = new ImageButton(this, new Point(ButtonGridPosition[2].X, ButtonGridPosition[3].Y));
buttonIBM.Image = new Bitmap(path + @"\BMP\IBM.bmp");
buttonIBM.ImageDown = new Bitmap(path + @"\BMP\IBM_Down.bmp");*/
buttonLock = new ImageButton(this, new Point(ButtonGridPosition[3].X, ButtonGridPosition[3].Y+6));
buttonLock.Image = new Bitmap(path + @"\BMP\lock 46x46.bmp");
buttonLock.ImageDown = new Bitmap(path + @"\BMP\lock 46x46_pressed.bmp");
PaintAllButton();
}
private void FindTaskManger() //判断是否存在任务管理器这个图标
{
if (File.Exists(@"\Windows\TaskMgr.exe"))
bShowTaskMgr = true;
}
private void PaintAllButton()
{
buttonSMS.Paint(gxBuffer);
buttonCalendar.Paint(gxBuffer);
buttonPhoto.Paint(gxBuffer);
buttonCamera.Paint(gxBuffer);
buttonCalculator.Paint(gxBuffer);
buttonMediaPlayer.Paint(gxBuffer);
buttonInternetExplorer.Paint(gxBuffer);
buttonNotes.Paint(gxBuffer);
buttonSettings.Paint(gxBuffer);
if (bShowTaskMgr)
buttonTaskManager.Paint(gxBuffer);
buttonClose.Paint(gxBuffer);
buttonPhone.Paint(gxBuffer);
buttonMail.Paint(gxBuffer);
buttonLock.Paint(gxBuffer);
//buttonIBM.Paint(gxBuffer);
}
private void MainMenu_Load(object sender, EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)
{
gxBuffer.Clear(this.BackColor);
//Draw background first
gxBuffer.DrawImage(backImageMainMenu, 0, 0);
PaintAllButton();
e.Graphics.DrawImage(offBitmap, 0, 0);//没有这一句,主菜单的整个背景就是白的
}
private bool CheckButtonPress()
{
if (buttonCalendar.IsPressedOneTime)
{
buttonCalendar.IsPressedOneTime = false;
ProcessExecute.Calendar();
return true;
}
if (buttonPhoto.IsPressedOneTime)
{
buttonPhoto.IsPressedOneTime = false;
ProcessExecute.Picture();
return true;
}
if (buttonCamera.IsPressedOneTime)
{
buttonCamera.IsPressedOneTime = false;
ProcessExecute.Camera();
return true;
}
if (buttonMail.IsPressedOneTime)
{
buttonMail.IsPressedOneTime = false;
ProcessExecute.Notes();
return true;
}
if (buttonPhone.IsPressedOneTime)
{
buttonPhone.IsPressedOneTime = false;
ProcessExecute.Phone();
return true;
}
if (buttonSMS.IsPressedOneTime)
{
ProcessExecute.Mail();
buttonSMS.IsPressedOneTime = false;
return true;
}
if (buttonCalculator.IsPressedOneTime)
{
ProcessExecute.Calc();
buttonCalculator.IsPressedOneTime = false;
return true;
}
if (buttonMediaPlayer.IsPressedOneTime)
{
ProcessExecute.MediaPlayer();
buttonMediaPlayer.IsPressedOneTime = false;
return true;
}
if (buttonInternetExplorer.IsPressedOneTime)
{
ProcessExecute.InternetExplorer();
buttonInternetExplorer.IsPressedOneTime = false;
return true;
}
if (buttonNotes.IsPressedOneTime)
{
ProcessExecute.Notes();
buttonNotes.IsPressedOneTime = false;
return true;
}
if (buttonSettings.IsPressedOneTime)
{
ProcessExecute.MediaPlayer();
buttonSettings.IsPressedOneTime = false;
return true;
}
if (bShowTaskMgr)
{
if (buttonTaskManager.IsPressedOneTime)
{
ProcessExecute.TaskManager();
buttonTaskManager.IsPressedOneTime = false;
return true;
}
}
if (buttonLock.IsPressedOneTime)
{
Close();
DialogResult = DialogResult.OK;
buttonLock.IsPressedOneTime = false;
return true;
}
if (buttonClose.IsPressedOneTime)
{
Close();
DialogResult = DialogResult.OK;
CloseApp = true;
return true;
}
return false;
}
private void PaintForm()
{
IntPtr activeWindowHandle = PlatformAPIs.GetForegroundWindow();
IntPtr thisWindowHandle = this.Handle;
if (activeWindowHandle != thisWindowHandle)//如果活动的窗口不是当前窗口
{
if (DialogResult != DialogResult.OK)
NeedRepaint = true; //在没有关的情况下需要重绘
}
else
{
if (NeedRepaint)
{
this.Invalidate();
NeedRepaint = false;
}
}
}
private void timerCheckButtonPressed_Tick(object sender, EventArgs e)//计时,检查按键的模式,不是点击之后及时响应
{
try
{
CheckButtonPress();
if (NeedRepaint)//判断是否需要重绘
{
this.Invalidate();
PaintForm();
return;
}
}
catch
{
Close();
}
}
private void MainMenu_Activated(object sender, EventArgs e)
{
NeedRepaint = true;
timerCheckButtonPressed_Tick(null, null);
}
private void MainMenu_Deactivate(object sender, EventArgs e)
{
NeedRepaint = false;
}
private void MainMenu_Paint(object sender, PaintEventArgs e)
{
NeedRepaint = true;
Console.WriteLine("MainMenu_Paint");
}
private void MainMenu_GotFocus(object sender, EventArgs e)
{
Console.WriteLine("MainMenu_GotFocus");
NeedRepaint = true;
timerCheckButtonPressed_Tick(null, null);
}
private void MainMenu_LostFocus(object sender, EventArgs e)
{
Console.WriteLine("MainMenu_LostFocus");
NeedRepaint = false;
}
private void MainMenu_Resize(object sender, EventArgs e)
{
NeedRepaint = true;
Console.WriteLine("MainMenu_Resize");
}
private void MainMenu_Closed(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void MainMenu_EnabledChanged(object sender, EventArgs e)
{
Console.WriteLine("MainMenu_EnabledChanged");
NeedRepaint = true;
timerCheckButtonPressed_Tick(null, null);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -