http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 22918|回复: 16

[C#皮肤] C#仿QQ皮肤-基窗体FunctionFormBase的实现

[复制链接]
发表于 2012-9-9 11:49:41 | 显示全部楼层 |阅读模式
导读部分
-------------------------------------------------------------------------------------------------------------
C#仿QQ皮肤-实现原理系列文章导航
http://www.sufeinet.com/forum.php?mod=viewthread&tid=2

一周要过去了,本来打算多写点的,还是时间不够啊,费话不多说,开始写代码,今天 我们要做的是一个窗体,这个窗体是基于窗体FormBase,就是我们上一节所说到的FormBase与基用户控件FormBase1的实现 里面的FormBase窗体, 有关 FormBase的实现还请大家去看相应文章,这里不再做过多的说明。我们先看一下实现的效果吧,第一张图是 实现,第二张是正常使用时的样子
FunctionFormBase1.png

Frombase16.jpg
下面看一下怎么实现吧,
第一步,创建窗体
我们右键单击文件夹选择添加窗体就行了,名称当时是“ FunctionFormBase”,然后单击确定,我们的窗体的大小不需要做任何的修改,那是因为那是继承自窗体FormBase而来的,上节我们讲过了, 他的大小是固定的,所以在这里不用再做设置;
只要这样一行继承的语句就OK了
[C#] 纯文本查看 复制代码
/// <summary>
    /// FunctionFormBase基窗体
    /// 是构造EntryForm和SkinForm窗体的基础
    /// </summary>
    public partial class FunctionFormBase : FormBase

第二步,窗体的UI布局实现
我们可以看到第一张图,就是窗体的UI布局,相信大家一看就能明白是怎么实现 的,我还是大致的说一下是怎么会事吧。窗体一共是三个Panel
代码实现为:
[C#] 纯文本查看 复制代码
 // 
            // ptbTopMiddle
            // 
            this.ptbTopMiddle.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ptbTopMiddle.Location = new System.Drawing.Point(10, 0);
            this.ptbTopMiddle.Name = "ptbTopMiddle";
            this.ptbTopMiddle.Size = new System.Drawing.Size(669, 31);
            this.ptbTopMiddle.TabIndex = 2;
            this.ptbTopMiddle.TabStop = false;

            // pnlBackGroup
            // 
            this.pnlBackGroup.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.pnlBackGroup.Dock = System.Windows.Forms.DockStyle.Fill;
            this.pnlBackGroup.Location = new System.Drawing.Point(0, 31);
            this.pnlBackGroup.Name = "pnlBackGroup";
            this.pnlBackGroup.Size = new System.Drawing.Size(689, 444);
            this.pnlBackGroup.TabIndex = 9;

            // 
            // ptbBottomMiddle
            // 
            this.ptbBottomMiddle.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ptbBottomMiddle.Location = new System.Drawing.Point(10, 0);
            this.ptbBottomMiddle.Name = "ptbBottomMiddle";
            this.ptbBottomMiddle.Size = new System.Drawing.Size(669, 37);
            this.ptbBottomMiddle.TabIndex = 3;

在ptbTopMiddle左面是一个lblText 右面是两个CommandButton,这个控件是 我自己写的实现方法后面会提到这里不做详细说明,在ptbTopMiddle的两端分别是两个Panel,用来实现窗体的边角,和低部的ptbBottomMiddle 形式是一样的,下面我给出这些控件的初始代码
[C#] 纯文本查看 复制代码
 // 
            // pnlRight
            // 
            this.pnlRight.Controls.Add(this.ptbRight);
            this.pnlRight.Dock = System.Windows.Forms.DockStyle.Right;
            this.pnlRight.Location = new System.Drawing.Point(687, 31);
            this.pnlRight.Name = "pnlRight";
            this.pnlRight.Size = new System.Drawing.Size(2, 444);
            this.pnlRight.TabIndex = 7;
            // 
            // ptbRight
            // 
            this.ptbRight.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ptbRight.Location = new System.Drawing.Point(0, 0);
            this.ptbRight.Name = "ptbRight";
            this.ptbRight.Size = new System.Drawing.Size(2, 444);
            this.ptbRight.TabIndex = 0;
            this.ptbRight.TabStop = false;
            // 
            // pnlLeft
            // 
            this.pnlLeft.Controls.Add(this.ptbLeft);
            this.pnlLeft.Dock = System.Windows.Forms.DockStyle.Left;
            this.pnlLeft.Location = new System.Drawing.Point(0, 31);
            this.pnlLeft.Name = "pnlLeft";
            this.pnlLeft.Size = new System.Drawing.Size(2, 444);
            this.pnlLeft.TabIndex = 6;
            // 
            // ptbLeft
            // 
            this.ptbLeft.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ptbLeft.Location = new System.Drawing.Point(0, 0);
            this.ptbLeft.Name = "ptbLeft";
            this.ptbLeft.Size = new System.Drawing.Size(2, 444);
            this.ptbLeft.TabIndex = 0;
            this.ptbLeft.TabStop = false;
            // 
            // ptbBottomRight
            // 
            this.ptbBottomRight.Dock = System.Windows.Forms.DockStyle.Right;
            this.ptbBottomRight.Location = new System.Drawing.Point(679, 0);
            this.ptbBottomRight.Name = "ptbBottomRight";
            this.ptbBottomRight.Size = new System.Drawing.Size(10, 37);
            this.ptbBottomRight.TabIndex = 2;
            this.ptbBottomRight.TabStop = false;
            // 
            // ptbBottomLeft
            // 
            this.ptbBottomLeft.Dock = System.Windows.Forms.DockStyle.Left;
            this.ptbBottomLeft.Location = new System.Drawing.Point(0, 0);
            this.ptbBottomLeft.Name = "ptbBottomLeft";
            this.ptbBottomLeft.Size = new System.Drawing.Size(10, 37);
            this.ptbBottomLeft.TabIndex = 0;
            this.ptbBottomLeft.TabStop = false;
            this.pnlBackGroup.TabIndex = 9;
            // 
            // lblText
            // 
            this.lblText.BackColor = System.Drawing.Color.Transparent;
            this.lblText.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lblText.Location = new System.Drawing.Point(27, 3);
            this.lblText.Name = "lblText";
            this.lblText.Size = new System.Drawing.Size(273, 24);
            this.lblText.TabIndex = 5;
            this.lblText.Text = "Text";
            this.lblText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.lblText.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Caption_MouseMove);
            this.lblText.MouseUp += new System.Windows.Forms.MouseEventHandler(this.caption_MouseUp);            // 
            // lblText
            // 
            this.lblText.BackColor = System.Drawing.Color.Transparent;
            this.lblText.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.lblText.Location = new System.Drawing.Point(27, 3);
            this.lblText.Name = "lblText";
            this.lblText.Size = new System.Drawing.Size(273, 24);
            this.lblText.TabIndex = 5;
            this.lblText.Text = "Text";
            this.lblText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.lblText.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Caption_MouseMove);
            this.lblText.MouseUp += new System.Windows.Forms.MouseEventHandler(this.caption_MouseUp);
            // 
            // pnlCaption
            // 
            this.pnlCaption.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.pnlCaption.Controls.Add(this.lblText);
            this.pnlCaption.Controls.Add(this.btnMin);
            this.pnlCaption.Controls.Add(this.btnClose);
            this.pnlCaption.Controls.Add(this.ptbTopMiddle);
            this.pnlCaption.Controls.Add(this.ptbTopRight);
            this.pnlCaption.Controls.Add(this.ptbTopLeft);
            this.pnlCaption.Dock = System.Windows.Forms.DockStyle.Top;
            this.pnlCaption.Location = new System.Drawing.Point(0, 0);
            this.pnlCaption.Name = "pnlCaption";
            this.pnlCaption.Size = new System.Drawing.Size(689, 31);
            this.pnlCaption.TabIndex = 5;
            // 
            // btnMin
            // 
            this.btnMin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.btnMin.BackColor = System.Drawing.Color.Transparent;
            this.btnMin.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(255)))));
            this.btnMin.Location = new System.Drawing.Point(610, 0);
            this.btnMin.MouseDownImage = null;
            this.btnMin.MouseMoveImage = null;
            this.btnMin.Name = "btnMin";
            this.btnMin.NormalImage = null;
            this.btnMin.Size = new System.Drawing.Size(31, 22);
            this.btnMin.TabIndex = 4;
            this.btnMin.ToolTip = "关闭";
            this.btnMin.Click += new System.EventHandler(this.btnMin_Click);
            // 
            // btnClose
            // 
            this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.btnClose.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(255)))));
            this.btnClose.Location = new System.Drawing.Point(642, 0);
            this.btnClose.MouseDownImage = null;
            this.btnClose.MouseMoveImage = null;
            this.btnClose.Name = "btnClose";
            this.btnClose.NormalImage = null;
            this.btnClose.Size = new System.Drawing.Size(37, 22);
            this.btnClose.TabIndex = 4;
            this.btnClose.ToolTip = "关闭";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // ptbTopMiddle
            // 
            this.ptbTopMiddle.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ptbTopMiddle.Location = new System.Drawing.Point(10, 0);
            this.ptbTopMiddle.Name = "ptbTopMiddle";
            this.ptbTopMiddle.Size = new System.Drawing.Size(669, 31);
            this.ptbTopMiddle.TabIndex = 2;
            this.ptbTopMiddle.TabStop = false;
            this.ptbTopMiddle.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Caption_MouseMove);
            this.ptbTopMiddle.MouseUp += new System.Windows.Forms.MouseEventHandler(this.caption_MouseUp);
            // 
            // ptbTopRight
            // 
            this.ptbTopRight.Dock = System.Windows.Forms.DockStyle.Right;
            this.ptbTopRight.Location = new System.Drawing.Point(679, 0);
            this.ptbTopRight.Name = "ptbTopRight";
            this.ptbTopRight.Size = new System.Drawing.Size(10, 31);
            this.ptbTopRight.TabIndex = 1;
            this.ptbTopRight.TabStop = false;
            // 
            // ptbTopLeft
            // 
            this.ptbTopLeft.Dock = System.Windows.Forms.DockStyle.Left;
            this.ptbTopLeft.Location = new System.Drawing.Point(0, 0);
            this.ptbTopLeft.Name = "ptbTopLeft";
            this.ptbTopLeft.Size = new System.Drawing.Size(10, 31);
            this.ptbTopLeft.TabIndex = 0;
            this.ptbTopLeft.TabStop = false;
            // 
            // pnlBottom
            // 
            this.pnlBottom.Controls.Add(this.ptbBottomMiddle);
            this.pnlBottom.Controls.Add(this.ptbBottomRight);
            this.pnlBottom.Controls.Add(this.ptbBottomLeft);
            this.pnlBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.pnlBottom.Location = new System.Drawing.Point(0, 475);
            this.pnlBottom.Name = "pnlBottom";
            this.pnlBottom.Size = new System.Drawing.Size(689, 37);
            this.pnlBottom.TabIndex = 8;


全部实现代码在这里,这些其实都 是系统自动生成的,大家简单的看一下就OK了,不知道 大家还记不记得上次说的FormBase窗体是上有控件的,那到这里为什么没有了呢,呵呵,其实不是没有了是我给移除了,呵呵,因为在这里根本用不上 ,我是通过Controls.Remove方法来实现 的,具体的代码如下所示
[C#] 纯文本查看 复制代码
//移除FormBase现有控件
            this.Controls.Remove(this.pnlRight);
            this.Controls.Remove(this.pnlLeft);
            this.Controls.Remove(this.pnlBackGroup);
            this.Controls.Remove(this.pnlCaption);
            this.Controls.Remove(this.pnlBottom);

好了我们的布局就到这里吧
第三步,ptbTopMiddle功能实现
因为我们的窗体是一个Panel,所以在移动和鼠标松开时的效果要处理一下,先说一下标题和最小化吧
标题是个Label,我们需要重写定义一下,怎么样来实现呢,我们只要重写一下窗体的Text属性就行了。实现如下
[C#] 纯文本查看 复制代码
//标题
        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
                if (this.lblText!=null)
                this.lblText.Text = this.Text;
            }
        }

这是标题那最小化呢?实现的方法有所不同,这里就不用再重写什么了,我们知道 窗体有现成的属性,所以实现就很方法了
[C#] 纯文本查看 复制代码
 //最小化
        private void btnMin_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

那大家应该会想了,那我怎么设置窗体 是否为可为最小化呢,难道是不让这个Button显示吗?呵呵
还是看代码吧
[C#] 纯文本查看 复制代码
 //最小化
        public new bool MinimizeBox
        {
            get
            {
                return base.MinimizeBox;
            }
            set
            {
                base.MinimizeBox = value;
                this.btnMin.Visible = value;
            }
        }


还有最后一个关闭按钮,这个更简单了,一个Close方法搞定
[C#] 纯文本查看 复制代码
//关闭按钮
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

第四步,窗体移动效果
我们的窗体是没有实际的标题的所以 在这里要处理一下移动时的效果
在这里用到了一些Api,具体的说明 请大家参考代码中的类文章Win32类 ,一共有两个方法一个是鼠标移动时的方法
[C#] 纯文本查看 复制代码
//移动标题时
        private void Caption_MouseMove(object sender, MouseEventArgs e)
        {
            ((Control)sender).Cursor = Cursors.Default;
            if (e.Button == MouseButtons.Left)
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(Handle, 274, 61440 + 9, 0);
            }
        }


另一个是鼠标MouseUp事件
[C#] 纯文本查看 复制代码
 //鼠标松开时
        private void caption_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && ((Control)sender).Cursor == Cursors.Default && e.Y <= SystemInformation.CaptionHeight)
            {
                Win32.TrackPopupMenu(Win32.GetSystemMenu(Handle, 0).ToInt32(), 2, Cursor.Position.X, Cursor.Position.Y, 0, Handle, 0);
            }
        }


第五步,窗体样式 实现
样式方面第一个重点就是Windows消息的处理,跟其实窗体的实现原理是一样的,不同 是WindowsApi和消息,因为消息在这里还要用的到所以我加了个ref,呵呵 ,ref(ref 关键字使参数按引用传递。其效果是,当控制权传递回调用方法时,在方法中对参数所做的任何更改都将反映在该变量中)
[C#] 纯文本查看 复制代码
 /// <summary>
        /// Windows消息处理
        /// </summary>
        /// <param name="m">Message</param>
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case Win32.WM_COMMAND:
                    Win32.SendMessage(Handle, Win32.WM_SYSCOMMAND, (int)m.WParam, (int)m.LParam);
                    break;
                case Win32.WM_SYSCOMMAND:
                    base.WndProc(ref m);

                    if (m.WParam.ToInt64() == Win32.SC_RESTORE)
                    {
                        this.Height += 6;
                        this.Width += 6;
                    }
                    else if (m.WParam.ToInt64() == Win32.SC_MAXIMIZE)
                    {
                        Application.DoEvents();
                    }

                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }

这个窗体的样式 除了Windows消息还有一个ReSetFormBitmap方法,因为这个方法是FromBase窗体 里我们在这里需要重写一下,
跟原先的方法实现是一样的,只是我要改几张图片,呵呵
[C#] 纯文本查看 复制代码
/// <summary>
        /// 设置窗体样式
        /// </summary>
        public override void ReSetFormBitmap()
        {
            this.pnlCaption.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordertm.bmp"));
            this.ptbTopLeft.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordertl.bmp"));
            this.ptbTopMiddle.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordertm.bmp"));
            this.ptbTopRight.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordertr.bmp"));

            this.ptbLeft.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.borderml.bmp"));
            this.ptbRight.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordermr.bmp"));

            this.ptbBottomLeft.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.borderbl.bmp"));
            this.ptbBottomMiddle.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.borderbm.bmp"));
            this.ptbBottomRight.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.borderbr.bmp"));

            this.pnlBackGroup.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bg.bmp"));

            Bitmap closeBitmap = new Bitmap(Bitmap.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.MainWin.Button.CloseBtn.bmp")));
            this.btnClose.NormalImage = closeBitmap.Clone(new Rectangle(0, 0, 37, 22), PixelFormat.Format64bppPArgb);
            this.btnClose.MouseMoveImage = closeBitmap.Clone(new Rectangle(37, 0, 37, 22), PixelFormat.Format64bppPArgb);
            this.btnClose.MouseDownImage = closeBitmap.Clone(new Rectangle(74, 0, 37, 22), PixelFormat.Format64bppPArgb);

            Bitmap minBitmap = new Bitmap(Bitmap.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.MainWin.Button.MinBtn.bmp")));
            this.btnMin.NormalImage = minBitmap.Clone(new Rectangle(0, 0, 31, 22), PixelFormat.Format64bppPArgb);
            this.btnMin.MouseMoveImage = minBitmap.Clone(new Rectangle(31, 0, 31, 22), PixelFormat.Format64bppPArgb);
            this.btnMin.MouseDownImage = minBitmap.Clone(new Rectangle(62, 0, 31, 22), PixelFormat.Format64bppPArgb);

            this.CurrentSkinColor = SkinColor.Default;
        }

文章中用到的所有素材请大家到源文件中去查找这里不再做过多的说明
到这里基本全部实现了,更具体的还请大家参考 源代码
老规矩这里附上窗体的所有实现 代码
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using CRD.Common;
using System.Drawing.Imaging;

namespace CRD.WinUI.Forms
{
    /// <summary>
    /// FunctionFormBase基窗体
    /// 是构造EntryForm和SkinForm窗体的基础
    /// </summary>
    public partial class FunctionFormBase : FormBase
    {
        //构造器
        public FunctionFormBase()
        {
            //设置默认的皮肤
            this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);

            InitializeComponent();

            //移除FormBase现有控件
            this.Controls.Remove(this.pnlRight);
            this.Controls.Remove(this.pnlLeft);
            this.Controls.Remove(this.pnlBackGroup);
            this.Controls.Remove(this.pnlCaption);
            this.Controls.Remove(this.pnlBottom);
        }

        /// <summary>
        /// Windows消息处理
        /// </summary>
        /// <param name="m">Message</param>
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case Win32.WM_COMMAND:
                    Win32.SendMessage(Handle, Win32.WM_SYSCOMMAND, (int)m.WParam, (int)m.LParam);
                    break;
                case Win32.WM_SYSCOMMAND:
                    base.WndProc(ref m);

                    if (m.WParam.ToInt64() == Win32.SC_RESTORE)
                    {
                        this.Height += 6;
                        this.Width += 6;
                    }
                    else if (m.WParam.ToInt64() == Win32.SC_MAXIMIZE)
                    {
                        Application.DoEvents();
                    }

                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }

        /// <summary>
        /// 设置窗体样式
        /// </summary>
        public override void ReSetFormBitmap()
        {
            this.pnlCaption.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordertm.bmp"));
            this.ptbTopLeft.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordertl.bmp"));
            this.ptbTopMiddle.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordertm.bmp"));
            this.ptbTopRight.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordertr.bmp"));

            this.ptbLeft.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.borderml.bmp"));
            this.ptbRight.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bordermr.bmp"));

            this.ptbBottomLeft.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.borderbl.bmp"));
            this.ptbBottomMiddle.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.borderbm.bmp"));
            this.ptbBottomRight.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.borderbr.bmp"));

            this.pnlBackGroup.BackgroundImage = Image.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.Common.dialog2009.bg.bmp"));

            Bitmap closeBitmap = new Bitmap(Bitmap.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.MainWin.Button.CloseBtn.bmp")));
            this.btnClose.NormalImage = closeBitmap.Clone(new Rectangle(0, 0, 37, 22), PixelFormat.Format64bppPArgb);
            this.btnClose.MouseMoveImage = closeBitmap.Clone(new Rectangle(37, 0, 37, 22), PixelFormat.Format64bppPArgb);
            this.btnClose.MouseDownImage = closeBitmap.Clone(new Rectangle(74, 0, 37, 22), PixelFormat.Format64bppPArgb);

            Bitmap minBitmap = new Bitmap(Bitmap.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream("CRD.WinUI.Resources.MainWin.Button.MinBtn.bmp")));
            this.btnMin.NormalImage = minBitmap.Clone(new Rectangle(0, 0, 31, 22), PixelFormat.Format64bppPArgb);
            this.btnMin.MouseMoveImage = minBitmap.Clone(new Rectangle(31, 0, 31, 22), PixelFormat.Format64bppPArgb);
            this.btnMin.MouseDownImage = minBitmap.Clone(new Rectangle(62, 0, 31, 22), PixelFormat.Format64bppPArgb);

            this.CurrentSkinColor = SkinColor.Default;
        }

        /// <summary>
        /// 重写的OnLoad
        /// </summary>
        protected override void OnLoad(EventArgs e)
        {
            this.Controls.Add(this.pnlRight);
            this.Controls.Add(this.pnlLeft);
            this.Controls.Add(this.pnlBackGroup);
            this.Controls.Add(this.pnlCaption);
            this.Controls.Add(this.pnlBottom);

            if (!DesignMode)
            {
                this.Hide();
            }

            base.OnLoad(e);

            Win32.SetWindowLong(this.Handle, -16,Win32.GetWindowLong(this.Handle,-16) -Win32.WS_MAXIMIZEBOX );

            this.Show();
        }

        //关闭按钮
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //最小化
        private void btnMin_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        //移动标题时
        private void Caption_MouseMove(object sender, MouseEventArgs e)
        {
            ((Control)sender).Cursor = Cursors.Default;
            if (e.Button == MouseButtons.Left)
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(Handle, 274, 61440 + 9, 0);
            }
        }

        //标题
        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
                if (this.lblText!=null)
                this.lblText.Text = this.Text;
            }
        }

        //最小化
        public new bool MinimizeBox
        {
            get
            {
                return base.MinimizeBox;
            }
            set
            {
                base.MinimizeBox = value;
                this.btnMin.Visible = value;
            }
        }

        //鼠标松开时
        private void caption_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && ((Control)sender).Cursor == Cursors.Default && e.Y <= SystemInformation.CaptionHeight)
            {
                Win32.TrackPopupMenu(Win32.GetSystemMenu(Handle, 0).ToInt32(), 2, Cursor.Position.X, Cursor.Position.Y, 0, Handle, 0);
            }
        }

    }
}

本帖被以下淘专辑推荐:

  • · 皮肤|主题: 15, 订阅: 0


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-1-27 18:55:44 | 显示全部楼层
如果能编译成dll作为控件使用就方便了,呵呵
 楼主| 发表于 2013-1-27 19:01:57 | 显示全部楼层
FXX 发表于 2013-1-27 18:55
如果能编译成dll作为控件使用就方便了,呵呵

源码不是更方便吗,还可以修改
发表于 2013-1-29 19:14:02 | 显示全部楼层
有些程序界面已经做好了,只想加皮肤资源的情况,源码就显得麻烦点
 楼主| 发表于 2013-3-8 17:50:11 | 显示全部楼层
FXX 发表于 2013-1-29 19:14
有些程序界面已经做好了,只想加皮肤资源的情况,源码就显得麻烦点

我是皮肤不是加进去就可以的,而是需要在开发的时候使用我的控件,你已经开发好的项目 是没有办法使用的
发表于 2013-7-10 13:32:31 | 显示全部楼层
那个皮肤类怎么用?
 楼主| 发表于 2013-7-10 14:15:23 | 显示全部楼层
fusheng 发表于 2013-7-10 13:32
那个皮肤类怎么用?

去看教程吧,里面有使用须知
发表于 2013-10-16 21:39:44 | 显示全部楼层
皮肤是怎么做的的??
 楼主| 发表于 2013-10-17 08:09:38 | 显示全部楼层

你下载源码看看就知道了
发表于 2013-10-17 12:32:10 | 显示全部楼层
我只是个菜鸟大二的学生
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-23 18:03

© 2014-2021

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