找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 3053|回复: 3

【.net、dll】皮肤ModernWolfSkin

[复制链接]

85

主题

175

回帖

3990

积分

用户组: 超级版主

No. 418

UID
418
精华
14
威望
53 点
宅币
1974 个
贡献
1582 次
宅之契约
0 份
在线时间
252 小时
注册时间
2014-8-9
发表于 2015-9-13 02:08:04 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
这是一个dll,基于dnet fx 4.5. 由vb.net编写
那么使用皮肤后的效果是这个样子:
捕获.JPG
3.JPG
捕获2.JPG
先扯淡,说说ModernWolfSkin各项花边:
关于为啥叫做Modern Wolf Skin?
有一个德国户外品牌叫做jack wolf skin,生产冲锋衣。。。等等。
名字酷酷的有没有?
微软在win8中引入的Metro UI也叫做New Windows UI或者Modern UI
是该UI的设计思路
所以,+到一起,诞生了Modern Wolf Skin。
既然是“狼皮”了,那么其中有个重要的类叫做:NCCoyoteSkin
顾名思义:NC郊狼皮(大家可以查一下郊狼的习性,这种狼生活与北美,生存能力极强,在其栖息地随处可见)
所以郊狼皮是一个很基础的类。
以后呢,还会实现更加漂亮的ArcticWolfSkin(北极狼皮)和支持dwm对NC进行扩展的支持Ribbon界面的CanisRufusSkin(红狼皮)

还有一个类叫做“土狗皮”(啊?肿么狼皮里冒出土狗皮)嘻嘻,大家自己去调用。
好了,接下来我跟大家分别讲述一下这个dll在vbdnet和csharp中的用法

在vbdnet中使用该dll非常容易,母语嘛。。
首先添加该dll的引用,如图:
1.JPG
然后,浏览,找到该dll 添加!
然后呢,在要使用皮肤的窗体类里边定义私有成员变量:
  1. Private WndSkn As New ModernWolfSkin.ModernWolfSkin.NCCoyoteSkin(Me)
复制代码

可以看见,这里初始化变量使用了NCCoyoteSkin(郊狼皮)的构造函数,并且传入一个Form自己的实例
(此处和csharp大有不同,而且cs傻X就傻X在这个地方。。。。等会说。。)
再然后,重载掉窗体类的WndProc函数:
  1. Protected Overrides Sub WndProc(ByRef m As Message)
  2.     MyBase.WndProc(m) '首先先让基类的WndProc处理message
  3.     WndSkn.HandleMsg(m) '然后让郊狼皮的实例处理message,使用郊狼皮类的实例的HandleMsg函数,传入m(我们不需要返回值,所以直接call它)
  4. End Sub
复制代码

那么代码至此,我们已经得到了这样一个窗体:
2.JPG
上源代码:
  1. Public Class Form1
  2.     Private WndSkn As New ModernWolfSkin.ModernWolfSkin.NCCoyoteSkin(Me)
  3.     Protected Overrides Sub WndProc(ByRef m As Message)
  4.         MyBase.WndProc(m)
  5.         WndSkn.HandleMsg(m)
  6.     End Sub
  7. End Class
复制代码

好了,最后是对皮肤的添油加醋。使用IDE的智能感知看看郊狼皮的成员函数和各项属性吧。
这里我放上公开函数,属性的“元数据”这是写dll时候留下的,大家可以利用其XML注释。
  1.         ''' <summary>
  2.         ''' The construct sub of the class.
  3.         ''' You can define and init this class as a member variable in a form class.
  4.         ''' </summary>
  5.         ''' <param name="TargetForm">Input form class name</param>
  6.         Public Sub New(ByRef TargetForm As Form)

  7.         ''' <summary>
  8.         ''' Render or redraw the non-client coyote skin now.
  9.         ''' </summary>
  10.         Public Sub RenderNow()

  11.         ''' <summary>
  12.         ''' Custom the titlebar of non-client coyote skin.
  13.         ''' </summary>
  14.         ''' <param name="BgColor">Titlebar's background color</param>
  15.         ''' <param name="Increment">Titlebar's height incremental value as pixels. Default value is 0 (no increment).</param>
  16.         ''' <param name="LightSytle">Controlboxe's Color. Value "True" for light color and "False" for dark color. This color will change with titlebar's backcolor.</param>
  17.         Public Sub SetTitleBar(ByVal BgColor As Color, Optional ByVal Increment As Long = 0, Optional ByVal LightSytle As Boolean = False)

  18.         ''' <summary>
  19.         ''' Mseeage handler. Must use it in form class's overrided procedure which called "WndProc". And this function must use after "MyBase.WndProc(m)".
  20.         ''' </summary>
  21.         ''' <param name="m">Import the message which called "m".</param>
  22.         ''' <returns></returns>
  23.         Public Overridable Function HandleMsg(ByRef m As Message) As Message

  24.         ''' <summary>
  25.         ''' Unpublished function, being test.
  26.         ''' We are sorry about that we cant provide arguments of this function.
  27.         ''' </summary>
  28.         ''' <param name="m">None</param>
  29.         ''' <param name="objWndProcX">None</param>
  30.         ''' <returns></returns>
  31.         Public Overridable Function InternationalTest_HandleMsg(ByRef m As Message, ByRef objWndProcX As PtrWndProcX) As Message

  32.         ''' <summary>
  33.         ''' Add icons for controlboxes
  34.         ''' </summary>
  35.         Public Function SetControlBoxIcons(ByVal Close0 As Icon,
  36.                                       ByVal Close1 As Icon,
  37.                                       ByVal Maximize0 As Icon,
  38.                                       ByVal Maximize1 As Icon,
  39.                                       ByVal Minimum0 As Icon,
  40.                                       ByVal Minimum1 As Icon,
  41.                                       ByVal Normal0 As Icon,
  42.                                       ByVal Normal1 As Icon) As Boolean
  43.         ''' <summary>
  44.         ''' Return The image of client area
  45.         ''' </summary>
  46.         ''' <returns>Image</returns>
  47.         Public Function GetClientImage() As Image

  48.         'Properties
  49.         ''' <summary>
  50.         ''' Get or set the controlbox's status.
  51.         ''' </summary>
  52.         ''' <returns>Integer</returns>
  53.         Public Property ControlBox() As EnumControlBox

  54.         ''' <summary>
  55.         ''' A boolean value that indicate visible of the border.
  56.         ''' </summary>
  57.         ''' <returns>Boolean</returns>
  58.         Public Property BorderVisible() As Boolean

  59.         ''' <summary>
  60.         ''' The color of the border.
  61.         ''' </summary>
  62.         ''' <returns>Color</returns>
  63.         Public Property BorderColor As Color

  64.         ''' <summary>
  65.         ''' Set the non-client background image.
  66.         ''' </summary>
  67.         Public WriteOnly Property NCBackgroundImage As Image

  68.         ''' <summary>
  69.         ''' The image aligment of non client area.
  70.         ''' </summary>
  71.         ''' <returns>Integer</returns>
  72.         Public Property BackgroundImageAlignment As EnumPictureAlignment

  73.         ''' <summary>
  74.         ''' Get or set a value of controlbox's image that from which way.
  75.         ''' </summary>
  76.         ''' <returns>Integer</returns>
  77.         Public Property ControlBoxImageSource As EnumImageSource

  78.         ''' <summary>
  79.         ''' Get or set close control box lighting colors.
  80.         ''' </summary>
  81.         ''' <returns>Color</returns>
  82.         Public Property ActiveCloseBoxColor As Color

  83.         ''' <summary>
  84.         '''  Get or set minimum control box lighting colors.
  85.         ''' </summary>
  86.         ''' <returns>Color</returns>
  87.         Public Property ActiveMinimumBoxColor As Color

  88.         ''' <summary>
  89.         '''  Get or set maximize control box lighting colors.
  90.         ''' </summary>
  91.         ''' <returns>Color</returns>
  92.         Public Property ActiveMaximizeBoxColor As Color

  93.         ''' <summary>
  94.         '''  Get or set close control box lighting colors.
  95.         ''' </summary>
  96.         ''' <returns>Color</returns>
  97.         Public Property UneabledControlBoxColor As Color

  98.         ''' <summary>
  99.         ''' To get the border width of a window.
  100.         ''' </summary>
  101.         ''' <returns>Long</returns>
  102.         Public ReadOnly Property BorderWidthPty As Long

  103.         ''' <summary>
  104.         ''' To get the title bar's height.
  105.         ''' </summary>
  106.         ''' <returns>Long</returns>
  107.         Public ReadOnly Property TitleBarHeightPty As Long

  108.         ''' <summary>
  109.         ''' Set non client border color.
  110.         ''' </summary>
  111.         ''' <returns>Color</returns>
  112.         Public Property NCColor As Color
复制代码

希望你拥有一张自己的“郊狼皮”!{:soso_e100:}

然后说到csharp对这个dll的调用。
不得不说,没有me的cs实现起来实在是超麻烦的。
那么总会有个办法,毕竟cs和vbdnet是亲兄弟,哥哥vbdnet的分享弟弟cs总有办法用吧。
首先,请添加引用。
这样实现:
(假设窗体类名叫Form1)
在program.cs的main里边会有这么一句话:Application.Run(new Form1());
也就是说,程序启动咋创建Form1的实例呢?cs很直接,没有用到变量。在Application的run函数里边,直接new了一个Form1
我们要想办法将Form1的实例传到Form1类自身里边以供郊狼皮的构造函数初始化使用。
第一,我们要在Form1类里边搞一个公共变量存放这个类自身的实例
  1. public Form frm;
复制代码

后边将 Application.Run(new Form1()); 替换成:
  1.             Form1 form1 = new Form1();
  2.             form1.frm = form1;
  3.             Application.Run(form1);
复制代码

好了,这样frm就能代替me使用了
那么,program.cs是酱紫的:
  1. using System;
  2. using System.Windows.Forms;

  3. namespace WindowsFormsApplication1
  4. {
  5.     static class Program
  6.     {
  7.         /// <summary>
  8.         /// 应用程序的主入口点。
  9.         /// </summary>
  10.         [STAThread]
  11.         static void Main()
  12.         {
  13.             Application.EnableVisualStyles();
  14.             Application.SetCompatibleTextRenderingDefault(false);
  15.             Form1 form1 = new Form1();
  16.             form1.frm = form1;
  17.             Application.Run(form1);
  18.         }
  19.     }
  20. }
复制代码

怎样给窗体披上郊狼皮呢,这里直接上代码(放心,我会注释大法):
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using ModernWolfSkin.ModernWolfSkin;

  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         
  16.         public Form frm; //自身实例
  17.         private NCCoyoteSkin CoyoteSkin; //和vbdnet一样,有木有?但是不能初始化,原因:
  18.         //frm是在Form1被实例化以后通过“form1.frm = form1;”(mian里边)一句被初始化的
  19.         //所以我们用的时候再去对其进行判断是否为null,而不能现在就放在郊狼皮的构造函数中对其init
  20.         //否则会导致传入了null
  21.         private bool bSkinReady = false; //搞个变量,判断皮肤是否已经准备好

  22.         public Form1() //构造函数,我们不去管它
  23.         {
  24.             InitializeComponent();
  25.         }

  26.         private bool LoadSkin() //这个函数就是判断frm这个form1自身实例是否初始化
  27.         {
  28.             if (frm != null)
  29.             {
  30.                 if (CoyoteSkin == null) //如果此时郊狼皮木有粗始化,那就粗屎画
  31.                     CoyoteSkin = new NCCoyoteSkin(ref frm);
  32.                 return true;
  33.             }
  34.             else
  35.                 return false;
  36.         }
  37.         protected override void WndProc(ref Message m) //和vbdnet的demo一样要重载Wndproc
  38.         {
  39.             base.WndProc(ref m);
  40.             if (bSkinReady) //一定要判断郊狼皮是否已经初始化
  41.                 CoyoteSkin.HandleMsg(ref m); //使用HandleMsg函数处理message,这里按饮引用传入
  42.         }

  43.         private void Form1_Load(object sender, EventArgs e)
  44.         {
  45.             //因为,如此这般 粗屎化完毕后,郊狼皮不能被披上!
  46.             //所以使用了一个蛋疼的办法:
  47.             //首先记录窗体原来的WindowState,再最小化窗体!然后等皮肤初始化完毕后恢复WindowState
  48.             //好蛋疼(流汗)木有办法呀(无奈)
  49.             FormWindowState OriginalWndStat = this.WindowState; //记录原来状态
  50.             this.WindowState = FormWindowState.Minimized; //最小化

  51.             bSkinReady = LoadSkin(); //加载皮肤
  52.             if(!bSkinReady) //皮肤木有加载OK
  53.                 MessageBox.Show("Failed To Load Skin!");

  54.             this.WindowState = OriginalWndStat; //恢复WindowState
  55.         }
  56.     }
  57. }
复制代码

好了基本上实现了,就是有点不舒服
那么对MWS皮肤的介绍到此为止,点个赞么,喵!{:soso_e154:}

1.0.0.1版本的dll下载地址:
ModernWolfSkin.dll (62 KB, 下载次数: 5)
ps:狼是很有趣的动物,请大家保护生态环境,不要剥夺它们的家
最后,请试用一下土狗皮!{:soso_e112:}
In the beginning I was not the best.
And the world was also not the best.
But I still know that I am who I am.
Because I think that it is good.
I have been working hard.
I have been keeping growth with the world.
And it was so.
回复

使用道具 举报

0

主题

5

回帖

292

积分

用户组: 中·技术宅

UID
910
精华
0
威望
1 点
宅币
285 个
贡献
0 次
宅之契约
0 份
在线时间
5 小时
注册时间
2015-6-12
发表于 2015-9-13 05:07:30 | 显示全部楼层
土狗...我要怎么吐槽?
不行.严肃点.

不能这样叫土狗:  叫本地狗
回复 赞! 靠!

使用道具 举报

85

主题

175

回帖

3990

积分

用户组: 超级版主

No. 418

UID
418
精华
14
威望
53 点
宅币
1974 个
贡献
1582 次
宅之契约
0 份
在线时间
252 小时
注册时间
2014-8-9
 楼主| 发表于 2015-9-13 16:07:42 | 显示全部楼层
Lv.1 液态物体 发表于 2015-9-13 05:07
土狗...我要怎么吐槽?
不行.严肃点.

捕获.JPG
你需要这样来上一句:
  1. Dim Qux As New ModernWolfSkin.NCMoleCricketSkin(1)
复制代码
In the beginning I was not the best.
And the world was also not the best.
But I still know that I am who I am.
Because I think that it is good.
I have been working hard.
I have been keeping growth with the world.
And it was so.
回复 赞! 靠!

使用道具 举报

0

主题

41

回帖

45

积分

用户组: 初·技术宅

UID
3351
精华
0
威望
2 点
宅币
0 个
贡献
0 次
宅之契约
0 份
在线时间
0 小时
注册时间
2018-1-14
发表于 2018-1-14 15:45:27 | 显示全部楼层
可以可以!!
回复

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-3-29 01:30 , Processed in 0.047339 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表