C#的皮肤skins详细使用图解

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

using log4net;

using Utility;

 

namespace WindowsFormsApplication

{

    ///<summary>

///<Author>JILONGLIANG</Author>

///<Date>2012/09/14</Date>

///<Description>处理皮肤Form窗体</Description>

///</summary>

    public partial class MainFrm : Form

    {

        string app_Path=AccessDirFileHelper.GetInstance().GetWindowsApplicationStartupPath();

        private int ComputerTime;//记录本机运行时间

        public MainFrm()

        {

            InitializeComponent();

        }

        /// <summary>

        /// 把设置IsMdiContainer = true;

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void TSMI_Login_Click(object sender, EventArgs e)

        {

           // LoginFrm loginFrm = new LoginFrm();

           // loginFrm.MdiParent = this;

           // loginFrm.Show();

        }

        /// <summary>

        ///

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void TSMI_TestDataBase_Click(object sender, EventArgs e)

        {

            //ConnectionSetupForm connectionSetupForm = new ConnectionSetupForm();

            //connectionSetupForm.MdiParent = this;

            //connectionSetupForm.Show();

        }

        /// <summary>

        /// 退出

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void TSMI_Logout_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }

        /// <summary>

        /// 重启

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void TSMI_Restart_Click(object sender, EventArgs e)

        {

            Application.Restart();

        }

        /// <summary>

        /// 加载

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void MainFrm_Load(object sender, EventArgs e)

        {

           AddChildMenuStripForWindowsStyle();

            //ILog log = log4net.LogManager.GetLogger(this.GetType());

            //log.Debug(e.ToString());

           ComputerTime = Environment.TickCount;//获取本机运行时间

        }

 

        /// <summary>

        /// 为风格菜单项添加子菜单

        /// </summary>

        private void AddChildMenuStripForWindowsStyle()

        {

            string curExePath = app_Path;

            string dir = curExePath + "\\Images";

            DirectoryInfo di = new DirectoryInfo(dir);

            int count = 1;

            //先清空下拉框

            this.TSMI_WindowSytle.DropDownItems.Clear();

            foreach (FileInfo fi in di.GetFiles())

            {

                if (fi.FullName.LastIndexOf(".gif") == fi.FullName.Length - 4)

                {

                    ToolStripMenuItem newTSMI = new ToolStripMenuItem("皮肤" + (count++));

                    newTSMI.Tag = fi.FullName;//保存图片

                    //订阅此菜单的鼠标悬浮事件

                    newTSMI.MouseHover += new EventHandler(TSMI_WindowSytle_MouseHover);

                    //订阅此菜单的鼠标离开事件

                    newTSMI.MouseLeave += new EventHandler(TSMI_WindowSytle_MouseLeave);

                    //订阅此菜单的鼠标点击事件

                    newTSMI.Click += new EventHandler(TSMI_WindowSytle_Click);

                    this.TSMI_WindowSytle.DropDownItems.Add(newTSMI);

                }

            }

        }

        /// <summary>

        /// 菜单的鼠标悬浮事件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void TSMI_WindowSytle_MouseHover(object sender, EventArgs e)

        {

            try

            {

                string picturePath = ((ToolStripMenuItem)sender).Tag.ToString();

                this.pictureBoxImages.BackgroundImage = Image.FromFile(picturePath);

                this.pictureBoxImages.BackgroundImageLayout = ImageLayout.Stretch;

                this.pictureBoxImages.Visible = true;

                Point point;

                if (MousePosition.Y >= 300)

                {

                    point = new Point(MousePosition.X + 62, 200);//调整位置

                }

                else

                {

                    point = new Point(MousePosition.X + 62, MousePosition.Y - 10);

                }

                this.pictureBoxImages.Location = point;

            }

            catch (Exception)

            {

                throw;

            }

        }

 

        /// <summary>

        /// 鼠标离开事件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void TSMI_WindowSytle_MouseLeave(object sender, EventArgs e)

        {

            this.pictureBoxImages.Visible = false;

        }

        /// <summary>

        /// 鼠标点击事件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void TSMI_WindowSytle_Click(object sender, EventArgs e)

        {

            try

            {

                string picturePath = ((ToolStripMenuItem)sender).Tag.ToString();

                string skinFillPath = picturePath.Substring(0, picturePath.Length - 3) + "ssk";

                this.skinEngine1.SkinFile = skinFillPath;

                this.Refresh();

            }

            catch (Exception)

            {

                throw;

            }

        }

        /// <summary>

        /// 当前系统应用时间

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void ShowApplicationTime_Tick(object sender, EventArgs e)

        {

            long CurTickValue = Environment.TickCount;

            long Difference = CurTickValue - ComputerTime;

 

            long ComputerHours, ComputerMinutes, ComputerSeconds;

            long ApplicationHours, ApplicationMinuters, ApplicationSecons;

 

            ComputerHours = (CurTickValue / (3600 * 999)) % 24;

            ComputerMinutes = (CurTickValue / (60 * 999)) % 60;

            ComputerSeconds = (CurTickValue / 999) % 60;

 

            ApplicationHours = (Difference / (3600 * 999)) % 24;//小时

            ApplicationMinuters = (Difference / (60 * 999)) % 60;//分钟

            ApplicationSecons = (Difference / 999) % 60;//

            this.ComputerSystemTime.Text = string.Format("本计算机已运行了{0}小时{1}{2}",

                ComputerHours.ToString(), ComputerMinutes.ToString(), ComputerSeconds.ToString());

            this.ApplicationFrmSystemTime.Text = string.Format("本应用程序已运行了{0}小时{1}{2}",

                ApplicationHours.ToString(), ApplicationMinuters.ToString(), ApplicationSecons.ToString());

        }

        /// <summary>

        /// 加载窗体的时候触发时间.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void CurrentNowTime_Tick(object sender, EventArgs e)

        {

            //this.CurrentNowTime.Enabled = true;//启用Elapsed事件生成

            //this.CurrentNowTime.Interval = 1000;//可以在窗体设置

            tssl_currNowTime.Text = Convert.ToString(DateTime.Now);

        }

       

    }

}

 

效果图

 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值