在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例Windows系统编程 → C# 窗体换肤全过程源码及皮肤生产器

C# 窗体换肤全过程源码及皮肤生产器

Windows系统编程

下载此实例
  • 开发语言:C#
  • 实例大小:0.22M
  • 下载次数:43
  • 浏览次数:588
  • 发布时间:2015-08-08
  • 实例类别:Windows系统编程
  • 发 布 人:kurosong
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 皮肤

实例介绍

【实例简介】

Delegate.rar(测试工程)

skinTest.rar(另一个测试工程)
JiuJiu.Ui.rar(换肤核心库)
Skinfactory.rar(皮肤文件生产器)
skin.rar(我自己做的几个皮肤文件)
希望能对你有所帮助,祝愉快!

【实例截图】

【核心代码】


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Drawing;
using System.Drawing.Drawing2D;


namespace JiuJiu.UI
{
    internal class CaptionSkin
    {
        private string skinfile;
        public string SkinFile
        {
            get { return skinfile; }
            set
            { 
                skinfile = value;
            }
        }
        HookWindow hook = null;
        private Form mainForm;
        bool controlBox;
        public Form MainForm
        {
            get { return mainForm; }
            set 
            {
                mainForm = value;
                controlBox = mainForm.ControlBox;
            }
        }


        public CaptionSkin()
        {
            
        }
        
        public CaptionSkin(Form mainForm)
            : this()
        {
            this.MainForm = mainForm;
        }

        public void InstallSkin()
        {            
            if (hook == null)
            {
                hook = new HookWindow(mainForm, this.skinfile);
                
            }
            hook.IsSkin = true;
            mainForm.ControlBox = false;
        }

        public void UninstallSkin()
        {
            if (hook != null)
            {
                hook.IsSkin = false;
                mainForm.ControlBox = controlBox;
            }            
        }
    }

    internal abstract class ControlSkin : IDisposable
    {
        protected Color TextColor, BackColorFocus, BackColorNoFocus;
        protected Control control;
        public abstract void Enter(object sender, EventArgs e);
        public abstract void Leave(object sender, EventArgs e);
        public abstract void MouseEnter(object sender, EventArgs e);
        public abstract void MouseLeave(object sender, EventArgs e);
        public abstract void MouseDown(object sender, EventArgs e);
        public abstract void MouseUp(object sender, EventArgs e);
        protected abstract void Paint(object sender, PaintEventArgs e);

        protected List<Bitmap> BMPs;
        public ControlSkin(Control c)
        {
            this.control = c;
            GetBMPs();
            GetColors();
        }

        protected virtual void GetColors()
        {
            TextColor = Color.Black;
            BackColorNoFocus = Color.FromArgb(210, 255, 210);
            BackColorFocus = Color.FromArgb(230, 255, 230);
        }
        protected abstract void GetBMPs();
        public virtual void Dispose()
        {
            if (BMPs != null && BMPs.Count > 0)
                for (int i = 0; i < BMPs.Count; i  )
                    BMPs[i].Dispose();
        }
        public abstract void SetStyle();
        public abstract void UnSetStyle();
    }

    internal class ButtonSkin : ControlSkin
    {
        public ButtonSkin(Button b)
            : base(b)
        {
        }
        protected override void GetBMPs()
        {
            BMPs = new List<Bitmap>();
            BMPs.Add(new Bitmap(@"e:\skin\btnnomal.bmp"));
            BMPs.Add(new Bitmap(@"e:\skin\btnenter.bmp"));
            BMPs.Add(new Bitmap(@"e:\skin\btndown.bmp"));
        }

        protected override void Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Bitmap bmp = new Bitmap("e:\\skin\\logo.png");
            g.DrawImage(bmp, g.ClipBounds);
        }
        public override void MouseEnter(object sender, EventArgs e)
        {
            Enter(null, null);
        }
        public override void MouseLeave(object sender, EventArgs e)
        {
            Leave(null, null);
        }
        public override void Enter(object sender, EventArgs e)
        {
            (control as Button).BackgroundImage = BMPs[1];
        }
        public override void Leave(object sender, EventArgs e)
        {
            control.BackgroundImage = BMPs[0];
        }
        public override void MouseDown(object sender, EventArgs e)
        {
            control.BackgroundImage = BMPs[2];
        }
        public override void MouseUp(object sneder, EventArgs e)
        {
            control.BackgroundImage = BMPs[1];
        }

        public override void SetStyle()
        {
            Button b = control as Button;
            b.BackgroundImage = BMPs[0];
            b.BackgroundImageLayout = ImageLayout.Stretch;
            b.Enter  = Enter;
            b.Leave  = Leave;
            b.MouseUp  = MouseUp;
            b.MouseDown  = MouseDown;
            b.MouseEnter  = MouseEnter;
            b.MouseLeave  = MouseLeave;
        }
        public override void UnSetStyle()
        {
            Button b = control as Button;
            b.Enter -= Enter;
            b.Leave -= Leave;
            b.MouseUp -= MouseUp;
            b.MouseDown -= MouseDown;
            b.MouseEnter -= MouseEnter;
            b.MouseLeave -= MouseLeave;
            b.BackgroundImage = null;

        }
    }

    internal class RadioSkin : ControlSkin
    {
        public RadioSkin(RadioButton rb)
            : base(rb)
        {
            if (!rb.AutoCheck)
                rb.AutoCheck = true;
        }
        public override void Enter(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void Leave(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseEnter(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseLeave(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseDown(object sender, EventArgs e)
        {
            RadioButton rb = control as RadioButton;
            if (rb.Checked)
                rb.Checked = false;
            else
                rb.Checked = true;
        }

        public override void MouseUp(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override void Paint(object sender, PaintEventArgs e)
        {
            RadioButton rb = control as RadioButton;
            if (rb.Checked)
                e.Graphics.DrawImage(BMPs[1], 0, 0, 13, 13);
            else
                e.Graphics.DrawImage(BMPs[0], 0, 0, 13, 13);
        }

        protected override void GetBMPs()
        {
            BMPs = new List<Bitmap>();
            BMPs.Add(new Bitmap("e:\\skin\\radio.png"));
            BMPs.Add(new Bitmap("e:\\skin\\radioenter.png"));
        }

        public override void SetStyle()
        {
            RadioButton rb = control as RadioButton;
            //rb.MouseDown  = MouseDown;
            rb.Paint  = Paint;            
        }

        public override void UnSetStyle()
        {
            RadioButton rb = control as RadioButton;
            //rb.MouseDown -= MouseDown;
            rb.Paint -= Paint;
        }
    }

    internal class CheckSkin : ControlSkin
    {
        public CheckSkin(CheckBox cb)
            : base(cb)
        {
            if (!cb.AutoCheck)
                cb.AutoCheck = true;
        }
        public override void Enter(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void Leave(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseEnter(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseLeave(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseDown(object sender, EventArgs e)
        {/*
            CheckBox cb = control as CheckBox;
            if (cb.Checked)
                cb.Checked = false;
            else
                cb.Checked = true;*/
        }

        public override void MouseUp(object sender, EventArgs e)
        {
            
        }

        protected override void Paint(object sender, PaintEventArgs e)
        {
            CheckBox cb = control as CheckBox;
            Graphics g = e.Graphics;
            if (cb.Checked)
            {
                g.DrawImage(BMPs[1], 0, 0, 13, 13);
            }
            else
            {
                g.DrawImage(BMPs[0], 0, 0, 13, 13);
            }
        }

        protected override void GetBMPs()
        {
            BMPs = new List<Bitmap>();
            BMPs.Add(new Bitmap(@"e:\skin\checkfalse.bmp"));
            BMPs.Add(new Bitmap(@"e:\skin\checktrue.bmp"));
        }

        public override void SetStyle()
        {
            control.Paint  = Paint;
        }

        public override void UnSetStyle()
        {
            control.Paint -= Paint;
        }
    }

    internal class EditSkin : ControlSkin
    {
        public EditSkin(Control txt)
            : base(txt)
        {

        }

        public override void Enter(object sender, EventArgs e)
        {
            control.BackColor = BackColorFocus;
        }

        public override void Leave(object sender, EventArgs e)
        {
            control.BackColor = BackColorNoFocus;
        }

        public override void MouseEnter(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseLeave(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseDown(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseUp(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override void Paint(object sender, PaintEventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override void GetBMPs()
        {
            //throw new NotImplementedException();
        }

        public override void SetStyle()
        {
            control.Enter  = Enter;
            control.Leave  = Leave;
            Leave(null, null);
        }

        public override void UnSetStyle()
        {
            control.Enter -= Enter;
            control.Leave -= Leave;
            control.ForeColor = SystemColors.WindowText;
            control.BackColor = SystemColors.ControlLightLight;
        }
    }


    internal class ListControlSkin : ControlSkin
    {
        public ListControlSkin(ListControl lcs)
            : base(lcs)
        {
        }
        public override void Enter(object sender, EventArgs e)
        {
            control.BackColor = BackColorFocus;
        }

        public override void Leave(object sender, EventArgs e)
        {
            control.BackColor = BackColorNoFocus;
        }

        public override void MouseEnter(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseLeave(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseDown(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseUp(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override void Paint(object sender, PaintEventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override void GetBMPs()
        {
            //throw new NotImplementedException();
        }

        public override void SetStyle()
        {
            control.Enter  = Enter;
            control.Leave  = Leave;
            Leave(null, null);
        }

        public override void UnSetStyle()
        {
            control.Enter -= Enter;
            control.Leave -= Leave;
            control.BackColor = SystemColors.ControlLightLight;
        }
    }

    internal class GridViewSkin : ControlSkin
    {
        public GridViewSkin(Control c)
            :base(c)
        {
        }
        public override void Enter(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void Leave(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseEnter(object sender, EventArgs e)
        {
            (control as DataGridView).BackgroundColor = this.BackColorFocus;
        }

        public override void MouseLeave(object sender, EventArgs e)
        {
            (control as DataGridView).BackgroundColor = this.BackColorNoFocus;
        }

        public override void MouseDown(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        public override void MouseUp(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override void Paint(object sender, PaintEventArgs e)
        {
            throw new NotImplementedException();
        }

        protected override void GetBMPs()
        {
            //throw new NotImplementedException();
        }

        public override void SetStyle()
        {
            (control as DataGridView).BackgroundColor = this.BackColorNoFocus;
            (control as DataGridView).MouseEnter  = MouseEnter;
            (control as DataGridView).MouseLeave  = MouseLeave;
        }

        public override void UnSetStyle()
        {
            (control as DataGridView).BackgroundColor = SystemColors.AppWorkspace;
            (control as DataGridView).MouseLeave -= MouseLeave;
            (control as DataGridView).MouseEnter -= MouseEnter;
        }
    }

    
}


标签: 皮肤

实例下载地址

C# 窗体换肤全过程源码及皮肤生产器

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警