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

📄 mainmenu.cs

📁 关于Microsoft Mobile IPhone_UI
💻 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;

namespace iPhoneUI
{
    public partial class MainMenu : Form
    {
        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;

        bool NeedRepaint = false;


        private InterceptButtonPressed InterceptButton = new InterceptButtonPressed();

        public MainMenu()
        {
            //http://judge.deviantart.com/art/iPhone-icons-47461337
            //http://flahorn.deviantart.com/art/iPhone-Theme-XP-69425212

            InitializeComponent();

            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\MainMenu.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");




            //4
            buttonPhone = new ImageButton(this, new Point(ButtonGridPosition[0].X, ButtonGridPosition[3].Y));
            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));
            buttonMail.Image = new Bitmap(path + @"\BMP\Mail 46x46.bmp");
            buttonMail.ImageDown = new Bitmap(path + @"\BMP\Mail 46x46_pressed.bmp");

            buttonLock = new ImageButton(this, new Point(ButtonGridPosition[3].X, ButtonGridPosition[3].Y));
            buttonLock.Image = new Bitmap(path + @"\BMP\lock 46x46.bmp");
            buttonLock.ImageDown = new Bitmap(path + @"\BMP\lock 46x46_pressed.bmp");

            PaintAllButton();



        }

        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);


            buttonPhone.Paint(gxBuffer);
            buttonMail.Paint(gxBuffer);
            buttonLock.Paint(gxBuffer);
        }

        private void MainMenu_Load(object sender, EventArgs e)
        {

        }

        [DllImport("coredll.dll", EntryPoint = "GetForegroundWindow", SetLastError = true)]
        internal static extern IntPtr GetForegroundWindow();

        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 (buttonLock.IsPressedOneTime)
            {
                Close();
                DialogResult = DialogResult.OK;

                buttonLock.IsPressedOneTime = false;
                return true;
            }
            return false;
        }

        private void PaintForm()
        {
           
            IntPtr activeWindowHandle = 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)
        {
            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)
        {
            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 + -