话说好久没有写了,呵呵,这几周太忙了,写好的新皮肤也没有整合完成,还得让大家再等两周,表示抱歉了,皮肤在使用中存在一些问题和解决方法请大家参才

 皮肤使用须知  (New)   一文章,有什么好的建议或是意见也希望大家提出来,希望能让更多的人参与的皮肤的设计和开发上。

       今天主要是看一下MainForm的实现而Main的实现与之相同,大家可以自己看一下源代码,或者我会在下次文章里提到一些,这个窗体是一个很重要的窗体,因为关于换肤的方法要在这里引用,使用皮肤的前提也是要使用这个窗体,所以是一个很重要的窗体,算是一个使用皮肤控件的基础吧;

     我们先看 一下它的布局吧

   

大家应该能看的出来,左上角是一个      Panel是用来做窗体的标题的,而右面的三个CommandButton是用来实现,最小化,最大化和关闭按钮的,

定部的Panel是工具一栏,而下面而是窗体 的主体部分了

   实现之后的效果是这样的

在这里还要感谢一位网友提供的图片素材,在这里谢谢了,最新的皮肤不会带有这些图片,但是上面具有这具功能 ,大家可以直接添加,因是作者留有版权,呵呵

  我们来看实现吧 所用的到图片大家可以在源代码里找到,我这里给出引用的图片代码大家可以根据代码查找

 

ExpandedBlockStart.gif 代码
namespace  CRD.WinUI.Forms
{
    
partial   class  Main
    {
        
///   <summary>
        
///  Required designer variable.
        
///   </summary>
         private  System.ComponentModel.IContainer components  =   null ;

        
///   <summary>
        
///  Clean up any resources being used.
        
///   </summary>
        
///   <param name="disposing"> true if managed resources should be disposed; otherwise, false. </param>
         protected   override   void  Dispose( bool  disposing)
        {
            
if  (disposing  &&  (components  !=   null ))
            {
                components.Dispose();
            }
            
base .Dispose(disposing);
        }

        
#region  Windows Form Designer generated code

        
///   <summary>
        
///  Required method for Designer support - do not modify
        
///  the contents of this method with the code editor.
        
///   </summary>
         private   void  InitializeComponent()
        {
            
this .components  =   new  System.ComponentModel.Container();
            
this .pnlCaption  =   new  System.Windows.Forms.Panel();
            
this .btnClose  =   new  CRD.WinUI.Misc.CommandButton();
            
this .btnMaxResore  =   new  CRD.WinUI.Misc.CommandButton();
            
this .btnMin  =   new  CRD.WinUI.Misc.CommandButton();
            
this .btnMenu  =   new  CRD.WinUI.Misc.CommandButton();
            
this .btnSkin  =   new  CRD.WinUI.Misc.CommandButton();
            
this .lblText  =   new  System.Windows.Forms.Label();
            
this .ptbTopRight  =   new  System.Windows.Forms.PictureBox();
            
this .ptbTopMiddle  =   new  System.Windows.Forms.PictureBox();
            
this .ptbTopLeft  =   new  System.Windows.Forms.PictureBox();
            
this .pnlBottom  =   new  System.Windows.Forms.Panel();
            
this .ptbBottomRight  =   new  System.Windows.Forms.PictureBox();
            
this .ptbBottomMiddle  =   new  System.Windows.Forms.PictureBox();
            
this .ptbBottomLeft  =   new  System.Windows.Forms.PictureBox();
            
this .pnlLeft  =   new  System.Windows.Forms.Panel();
            
this .ptbLeft  =   new  System.Windows.Forms.PictureBox();
            
this .pnlRight  =   new  System.Windows.Forms.Panel();
            
this .ptbRight  =   new  System.Windows.Forms.PictureBox();
            
this .GCtimer  =   new  System.Windows.Forms.Timer( this .components);
            
this .pnlBackground  =   new  CRD.WinUI.Misc.panel();
            
this .pnlCaption.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbTopRight)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbTopMiddle)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbTopLeft)).BeginInit();
            
this .pnlBottom.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbBottomRight)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbBottomMiddle)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbBottomLeft)).BeginInit();
            
this .pnlLeft.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbLeft)).BeginInit();
            
this .pnlRight.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbRight)).BeginInit();
            
this .SuspendLayout();
            
//  
            
//  pnlCaption
            
//  
             this .pnlCaption.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
this .pnlCaption.Controls.Add( this .btnClose);
            
this .pnlCaption.Controls.Add( this .btnMaxResore);
            
this .pnlCaption.Controls.Add( this .btnMin);
            
this .pnlCaption.Controls.Add( this .btnMenu);
            
this .pnlCaption.Controls.Add( this .btnSkin);
            
this .pnlCaption.Controls.Add( this .lblText);
            
this .pnlCaption.Controls.Add( this .ptbTopRight);
            
this .pnlCaption.Controls.Add( this .ptbTopMiddle);
            
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( 592 112 );
            
this .pnlCaption.TabIndex  =   0 ;
            
//  
            
//  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( 548 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  =   3 ;
            
this .btnClose.ToolTip  =   " 关闭 " ;
            
this .btnClose.Click  +=   new  System.EventHandler( this .btnClose_Click);
            
//  
            
//  btnMaxResore
            
//  
             this .btnMaxResore.Anchor  =  ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top  |  System.Windows.Forms.AnchorStyles.Right)));
            
this .btnMaxResore.ImageTransparentColor  =  System.Drawing.Color.FromArgb((( int )((( byte )( 255 )))), (( int )((( byte )( 0 )))), (( int )((( byte )( 255 )))));
            
this .btnMaxResore.Location  =   new  System.Drawing.Point( 516 0 );
            
this .btnMaxResore.MouseDownImage  =   null ;
            
this .btnMaxResore.MouseMoveImage  =   null ;
            
this .btnMaxResore.Name  =   " btnMaxResore " ;
            
this .btnMaxResore.NormalImage  =   null ;
            
this .btnMaxResore.Size  =   new  System.Drawing.Size( 32 22 );
            
this .btnMaxResore.TabIndex  =   3 ;
            
this .btnMaxResore.ToolTip  =   " 最大化 " ;
            
this .btnMaxResore.Click  +=   new  System.EventHandler( this .btnMaxResore_Click);
            
//  
            
//  btnMin
            
//  
             this .btnMin.Anchor  =  ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top  |  System.Windows.Forms.AnchorStyles.Right)));
            
this .btnMin.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
this .btnMin.ImageTransparentColor  =  System.Drawing.Color.FromArgb((( int )((( byte )( 255 )))), (( int )((( byte )( 0 )))), (( int )((( byte )( 255 )))));
            
this .btnMin.Location  =   new  System.Drawing.Point( 485 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  =   3 ;
            
this .btnMin.ToolTip  =   " 最小化 " ;
            
this .btnMin.Click  +=   new  System.EventHandler( this .btnMin_Click);
            
//  
            
//  btnMenu
            
//  
             this .btnMenu.Anchor  =  ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top  |  System.Windows.Forms.AnchorStyles.Right)));
            
this .btnMenu.BackColor  =  System.Drawing.Color.Transparent;
            
this .btnMenu.ImageTransparentColor  =  System.Drawing.Color.Empty;
            
this .btnMenu.Location  =   new  System.Drawing.Point( 428 6 );
            
this .btnMenu.MouseDownImage  =   null ;
            
this .btnMenu.MouseMoveImage  =   null ;
            
this .btnMenu.Name  =   " btnMenu " ;
            
this .btnMenu.NormalImage  =   null ;
            
this .btnMenu.Size  =   new  System.Drawing.Size( 40 14 );
            
this .btnMenu.TabIndex  =   5 ;
            
this .btnMenu.ToolTip  =   null ;
            
this .btnMenu.MouseClick  +=   new  System.Windows.Forms.MouseEventHandler( this .btnMenu_MouseClick);
            
//  
            
//  btnSkin
            
//  
             this .btnSkin.Anchor  =  ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top  |  System.Windows.Forms.AnchorStyles.Right)));
            
this .btnSkin.BackColor  =  System.Drawing.Color.Transparent;
            
this .btnSkin.ImageTransparentColor  =  System.Drawing.Color.Empty;
            
this .btnSkin.Location  =   new  System.Drawing.Point( 374 6 );
            
this .btnSkin.MouseDownImage  =   null ;
            
this .btnSkin.MouseMoveImage  =   null ;
            
this .btnSkin.Name  =   " btnSkin " ;
            
this .btnSkin.NormalImage  =   null ;
            
this .btnSkin.Size  =   new  System.Drawing.Size( 40 14 );
            
this .btnSkin.TabIndex  =   5 ;
            
this .btnSkin.ToolTip  =   null ;
            
this .btnSkin.Click  +=   new  System.EventHandler( this .btnSkin_Click);
            
//  
            
//  lblText
            
//  
             this .lblText.BackColor  =  System.Drawing.Color.Transparent;
            
this .lblText.Location  =   new  System.Drawing.Point( 16 2 );
            
this .lblText.Name  =   " lblText " ;
            
this .lblText.Size  =   new  System.Drawing.Size( 283 26 );
            
this .lblText.TabIndex  =   0 ;
            
this .lblText.TextAlign  =  System.Drawing.ContentAlignment.MiddleLeft;
            
this .lblText.DoubleClick  +=   new  System.EventHandler( this .Caption_DouClick);
            
this .lblText.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .lblText_MouseMove);
            
this .lblText.MouseUp  +=   new  System.Windows.Forms.MouseEventHandler( this .Caption_MouseUp);
            
//  
            
//  ptbTopRight
            
//  
             this .ptbTopRight.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
this .ptbTopRight.Dock  =  System.Windows.Forms.DockStyle.Right;
            
this .ptbTopRight.Location  =   new  System.Drawing.Point( 584 0 );
            
this .ptbTopRight.Name  =   " ptbTopRight " ;
            
this .ptbTopRight.Size  =   new  System.Drawing.Size( 8 112 );
            
this .ptbTopRight.TabIndex  =   2 ;
            
this .ptbTopRight.TabStop  =   false ;
            
this .ptbTopRight.DoubleClick  +=   new  System.EventHandler( this .Caption_DouClick);
            
this .ptbTopRight.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .ptbTopRight_MouseMove);
            
this .ptbTopRight.MouseUp  +=   new  System.Windows.Forms.MouseEventHandler( this .Caption_MouseUp);
            
//  
            
//  ptbTopMiddle
            
//  
             this .ptbTopMiddle.BackColor  =  System.Drawing.SystemColors.Control;
            
this .ptbTopMiddle.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
this .ptbTopMiddle.Dock  =  System.Windows.Forms.DockStyle.Fill;
            
this .ptbTopMiddle.Location  =   new  System.Drawing.Point( 0 0 );
            
this .ptbTopMiddle.Name  =   " ptbTopMiddle " ;
            
this .ptbTopMiddle.Size  =   new  System.Drawing.Size( 592 112 );
            
this .ptbTopMiddle.TabIndex  =   1 ;
            
this .ptbTopMiddle.TabStop  =   false ;
            
this .ptbTopMiddle.DoubleClick  +=   new  System.EventHandler( this .Caption_DouClick);
            
this .ptbTopMiddle.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .ptbTopMiddle_MouseMove);
            
this .ptbTopMiddle.MouseUp  +=   new  System.Windows.Forms.MouseEventHandler( this .Caption_MouseUp);
            
//  
            
//  ptbTopLeft
            
//  
             this .ptbTopLeft.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
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( 0 112 );
            
this .ptbTopLeft.TabIndex  =   0 ;
            
this .ptbTopLeft.TabStop  =   false ;
            
this .ptbTopLeft.DoubleClick  +=   new  System.EventHandler( this .Caption_DouClick);
            
this .ptbTopLeft.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .ptbTopLeft_MouseMove);
            
this .ptbTopLeft.MouseUp  +=   new  System.Windows.Forms.MouseEventHandler( this .Caption_MouseUp);
            
//  
            
//  pnlBottom
            
//  
             this .pnlBottom.Controls.Add( this .ptbBottomRight);
            
this .pnlBottom.Controls.Add( this .ptbBottomMiddle);
            
this .pnlBottom.Controls.Add( this .ptbBottomLeft);
            
this .pnlBottom.Dock  =  System.Windows.Forms.DockStyle.Bottom;
            
this .pnlBottom.Location  =   new  System.Drawing.Point( 0 413 );
            
this .pnlBottom.Name  =   " pnlBottom " ;
            
this .pnlBottom.Size  =   new  System.Drawing.Size( 592 10 );
            
this .pnlBottom.TabIndex  =   2 ;
            
//  
            
//  ptbBottomRight
            
//  
             this .ptbBottomRight.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
this .ptbBottomRight.Dock  =  System.Windows.Forms.DockStyle.Right;
            
this .ptbBottomRight.Location  =   new  System.Drawing.Point( 584 0 );
            
this .ptbBottomRight.Name  =   " ptbBottomRight " ;
            
this .ptbBottomRight.Size  =   new  System.Drawing.Size( 8 10 );
            
this .ptbBottomRight.TabIndex  =   1 ;
            
this .ptbBottomRight.TabStop  =   false ;
            
this .ptbBottomRight.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .ptbBottomRight_MouseMove);
            
//  
            
//  ptbBottomMiddle
            
//  
             this .ptbBottomMiddle.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
this .ptbBottomMiddle.Dock  =  System.Windows.Forms.DockStyle.Fill;
            
this .ptbBottomMiddle.Location  =   new  System.Drawing.Point( 8 0 );
            
this .ptbBottomMiddle.Name  =   " ptbBottomMiddle " ;
            
this .ptbBottomMiddle.Size  =   new  System.Drawing.Size( 584 10 );
            
this .ptbBottomMiddle.TabIndex  =   2 ;
            
this .ptbBottomMiddle.TabStop  =   false ;
            
this .ptbBottomMiddle.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .ptbBottomMiddle_MouseMove);
            
//  
            
//  ptbBottomLeft
            
//  
             this .ptbBottomLeft.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
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( 8 10 );
            
this .ptbBottomLeft.TabIndex  =   0 ;
            
this .ptbBottomLeft.TabStop  =   false ;
            
this .ptbBottomLeft.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .ptbBottomLeft_MouseMove);
            
//  
            
//  pnlLeft
            
//  
             this .pnlLeft.Controls.Add( this .ptbLeft);
            
this .pnlLeft.Dock  =  System.Windows.Forms.DockStyle.Left;
            
this .pnlLeft.Location  =   new  System.Drawing.Point( 0 112 );
            
this .pnlLeft.Name  =   " pnlLeft " ;
            
this .pnlLeft.Size  =   new  System.Drawing.Size( 6 301 );
            
this .pnlLeft.TabIndex  =   3 ;
            
//  
            
//  ptbLeft
            
//  
             this .ptbLeft.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
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( 6 301 );
            
this .ptbLeft.TabIndex  =   0 ;
            
this .ptbLeft.TabStop  =   false ;
            
this .ptbLeft.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .ptbLeft_MouseMove);
            
//  
            
//  pnlRight
            
//  
             this .pnlRight.Controls.Add( this .ptbRight);
            
this .pnlRight.Dock  =  System.Windows.Forms.DockStyle.Right;
            
this .pnlRight.Location  =   new  System.Drawing.Point( 587 112 );
            
this .pnlRight.Name  =   " pnlRight " ;
            
this .pnlRight.Size  =   new  System.Drawing.Size( 5 301 );
            
this .pnlRight.TabIndex  =   4 ;
            
//  
            
//  ptbRight
            
//  
             this .ptbRight.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
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( 5 301 );
            
this .ptbRight.TabIndex  =   0 ;
            
this .ptbRight.TabStop  =   false ;
            
this .ptbRight.MouseMove  +=   new  System.Windows.Forms.MouseEventHandler( this .ptbRight_MouseMove);
            
//  
            
//  GCtimer
            
//  
             this .GCtimer.Interval  =   6000 ;
            
this .GCtimer.Tick  +=   new  System.EventHandler( this .GCtimer_Tick);
            
//  
            
//  pnlBackground
            
//  
             this .pnlBackground.BackgroundImageLayout  =  System.Windows.Forms.ImageLayout.Stretch;
            
this .pnlBackground.Dock  =  System.Windows.Forms.DockStyle.Fill;
            
this .pnlBackground.ImageTransparentColor  =  System.Drawing.Color.Empty;
            
this .pnlBackground.Location  =   new  System.Drawing.Point( 6 112 );
            
this .pnlBackground.Name  =   " pnlBackground " ;
            
this .pnlBackground.Size  =   new  System.Drawing.Size( 581 301 );
            
this .pnlBackground.TabIndex  =   5 ;
            
//  
            
//  Main
            
//  
             this .AutoScaleDimensions  =   new  System.Drawing.SizeF(6F, 12F);
            
this .AutoScaleMode  =  System.Windows.Forms.AutoScaleMode.Font;
            
this .ClientSize  =   new  System.Drawing.Size( 592 423 );
            
this .Controls.Add( this .pnlBackground);
            
this .Controls.Add( this .pnlRight);
            
this .Controls.Add( this .pnlLeft);
            
this .Controls.Add( this .pnlBottom);
            
this .Controls.Add( this .pnlCaption);
            
this .Location  =   new  System.Drawing.Point( 0 0 );
            
this .Name  =   " Main " ;
            
this .StartPosition  =  System.Windows.Forms.FormStartPosition.CenterScreen;
            
this .Text  =   " MainForm " ;
            
this .ResizeEnd  +=   new  System.EventHandler( this .MainForm_ResizeEnd);
            
this .pnlCaption.ResumeLayout( false );
            ((System.ComponentModel.ISupportInitialize)(
this .ptbTopRight)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbTopMiddle)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbTopLeft)).EndInit();
            
this .pnlBottom.ResumeLayout( false );
            ((System.ComponentModel.ISupportInitialize)(
this .ptbBottomRight)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbBottomMiddle)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(
this .ptbBottomLeft)).EndInit();
            
this .pnlLeft.ResumeLayout( false );
            ((System.ComponentModel.ISupportInitialize)(
this .ptbLeft)).EndInit();
            
this .pnlRight.ResumeLayout( false );
            ((System.ComponentModel.ISupportInitialize)(
this .ptbRight)).EndInit();
            
this .ResumeLayout( false );

        }

        
#endregion

        
internal  System.Windows.Forms.Panel pnlCaption;
        
internal  System.Windows.Forms.PictureBox ptbTopRight;
        
internal  System.Windows.Forms.PictureBox ptbTopMiddle;
        
internal  System.Windows.Forms.Panel pnlBottom;
        
internal  System.Windows.Forms.PictureBox ptbBottomMiddle;
        
internal  System.Windows.Forms.PictureBox ptbBottomRight;
        
internal  System.Windows.Forms.PictureBox ptbBottomLeft;
        
internal  System.Windows.Forms.Panel pnlLeft;
        
internal  System.Windows.Forms.PictureBox ptbLeft;
        
internal  System.Windows.Forms.Panel pnlRight;
        
internal  System.Windows.Forms.PictureBox ptbRight;
        
internal  CRD.WinUI.Misc.CommandButton btnClose;
        
internal  CRD.WinUI.Misc.CommandButton btnMaxResore;
        
internal  CRD.WinUI.Misc.CommandButton btnMin;
        
internal  System.Windows.Forms.Timer GCtimer;
        
internal  CRD.WinUI.Misc.CommandButton btnMenu;
        
internal  CRD.WinUI.Misc.CommandButton btnSkin;
        
protected  CRD.WinUI.Misc.panel pnlBackground;
        
internal  System.Windows.Forms.Label lblText;
        
internal  System.Windows.Forms.PictureBox ptbTopLeft;

    }
}

 

 

先来看一下构造器吧

 

ExpandedBlockStart.gif 代码
  this .SetStyle(ControlStyles.DoubleBuffer  |  ControlStyles.AllPaintingInWmPaint,  true );
            InitializeComponent();
            
this .Controls.Remove( this .pnlBackground);
            
this .Controls.Remove( this .pnlRight);
            
this .Controls.Remove( this .pnlLeft);
            
this .Controls.Remove( this .pnlBottom);
            
this .Controls.Remove( this .pnlCaption);

 

老样子还是先移除之前基础窗体上的控件

在这里我实现 了一个接口IMainForm 用来定义窗体的规范,

大家也可以看一下这个接口的主要代码

ExpandedBlockStart.gif 代码
  // 窗体接口
     public   interface  IMainForm
    {
        
void  PerformChangeSkinColor();
        
void  PerformChangeSkinColor(SkinColor skinColor);
        
void  PerformChangeBackgroundStripe(BackgroundStripe backgroundStripe);
        
void  PerformAllFormChangeSkinColor(SkinColor skinColor);

        SkinColor CurrentSkinColor {
get ; set ;}

        Color MainFormBackGroundColor { 
get ; }
        Color MainFormBackGroundColor2 { 
get ; }
        Color ControlBackColor { 
get ; }
        Color ControlBorderBackColor { 
get ; }
    }

 

 

本窗是继承自FormBase窗体而来的,如果大家看过它的实现应该不难明白为什么要这样处理构造器了

处理窗体标题栏的方法

 

ExpandedBlockStart.gif 代码
  public   override   string  Text
        {
            
get
            {
                
return   base .Text;
            }
            
set
            {
                
base .Text  =  value;
                
if  (lblText  !=   null )
                    
this .lblText.Text  =  value;
            }
        }

 

 

上面Panel皮肤处理

主体Panel处理

 

ExpandedBlockStart.gif 代码
   public  Color ControlBackColor
        {
            
get
            {
                
if  ( this .pnlBackground.BackgroundImage  !=   null )
                {
                    Bitmap bitmap 
=   new  Bitmap( this .pnlBackground.BackgroundImage);
                    
return  bitmap.GetPixel( 20 30 );
                }
                
else
                {
                    
return  SystemColors.Control;
                }
            }
        }

        
public  Color ControlBorderBackColor
        {
            
get
            {
                
if  ( this .ptbTopMiddle.BackgroundImage  !=   null )
                {
                    Bitmap bitmap 
=   new  Bitmap( this .ptbTopMiddle.BackgroundImage);
                    
return  bitmap.GetPixel( 1 80 );
                }
                
else
                {
                    
return  SystemColors.Control;
                }
            }
        }

        
public  Color MainFormBorderColor
        {
            
get
            {
                
if  ( this .ptbTopLeft.BackgroundImage  !=   null )
                {
                    Bitmap bitmap 
=   new  Bitmap( this .ptbTopLeft.BackgroundImage);
                    
return  bitmap.GetPixel( 1 20 );
                }
                
else
                {
                    
return  SystemColors.Control;
                }
            }
        }

        

 

 

下面是Windows消息的处理方法

 

ExpandedBlockStart.gif 代码
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 ;
                        
this .btnMaxResore.NormalImage  =  maxBitmap.Clone( new  Rectangle( 0 0 32 22 ), PixelFormat.Format64bppPArgb);
                        
this .btnMaxResore.MouseMoveImage  =  maxBitmap.Clone( new  Rectangle( 32 0 32 22 ), PixelFormat.Format64bppPArgb);
                        
this .btnMaxResore.MouseDownImage  =  maxBitmap.Clone( new  Rectangle( 64 0 32 22 ), PixelFormat.Format64bppPArgb);
                        
this .btnMaxResore.ToolTip  =   " 还原 " ;

                        Shared.ChangeSkinColor(Shared.CurrentSkinColor, 
this .btnMaxResore,  true );
                    }
                    
else   if  (m.WParam.ToInt64()  ==  Win32.SC_MAXIMIZE)
                    {
                        Application.DoEvents();
                        
this .btnMaxResore.NormalImage  =  resoreBitmap.Clone( new  Rectangle( 0 0 32 22 ), PixelFormat.Format64bppPArgb);
                        
this .btnMaxResore.MouseMoveImage  =  resoreBitmap.Clone( new  Rectangle( 32 0 32 22 ), PixelFormat.Format64bppPArgb);
                        
this .btnMaxResore.MouseDownImage  =  resoreBitmap.Clone( new  Rectangle( 64 0 32 22 ), PixelFormat.Format64bppPArgb);
                        
this .btnMaxResore.ToolTip  =   " 最大化 " ;

                        Shared.ChangeSkinColor(Shared.CurrentSkinColor, 
this .btnMaxResore,  true );
                    }

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



代码
  
public  Color MainFormBackGroundColor
        {
            
get
            {
                
if  ( this .ptbTopLeft.BackgroundImage  !=   null )
                {
                    Bitmap bitmap 
=   new  Bitmap( this .ptbTopLeft.BackgroundImage);
                    
this .BackColor  =  bitmap.GetPixel( 20 15 );
                    
return   this .BackColor;
                }
                
else
                {
                    
return  SystemColors.Control;
                }
            }
        }

 

 

 OnLoad方法这里加载 了一些默认要显示的图片

 

ExpandedBlockStart.gif 代码
  protected   override   void  OnLoad(EventArgs e)
        {
            
this .Controls.Add( this .pnlBackground);
            
this .Controls.Add( this .pnlRight);
            
this .Controls.Add( this .pnlLeft);
            
this .Controls.Add( this .pnlBottom);
            
this .Controls.Add( this .pnlCaption);

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

            resoreBitmap 
=   new  Bitmap(Bitmap.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream( " CRD.WinUI.Resources.MainWin.Button.RestrBtn.bmp " )));
            maxBitmap 
=   new  Bitmap(Bitmap.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream( " CRD.WinUI.Resources.MainWin.Button.MaxBtn.bmp " )));

            skinButton 
=   new  Bitmap(Bitmap.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream( " CRD.WinUI.Resources.MainWin.Button.ColorBtn.png " )));
            menuButton 
=   new  Bitmap(Bitmap.FromStream(Shared.AssemblyWinUI.GetManifestResourceStream( " CRD.WinUI.Resources.MainWin.Button.MenuBtn.png " )));

            
this .lblText.Text  =   this .Text;

            Application.DoEvents();

            
base .OnLoad(e);

            
if  ( ! DesignMode)
            {
                
int  maxWidth  =  Screen.GetWorkingArea( this ).Width  +   15 ;
                
int  maxHeight  =  Screen.GetWorkingArea( this ).Height  +   8 ;
               
                
this .MaximumSize  =   new  Size(SystemInformation.WorkingArea.Size.Width  +   15 , SystemInformation.WorkingArea.Size.Height  +   8 );
            }

            Application.DoEvents();
            
this .Show();
        }

 

因为我们是窗体 是没有标题栏的,所 以我们要处理一个当拖动上面Panel时要让窗体要着移动,还有就 是在移动的过程中要刷新一下皮肤

下面一全部的处理方法

 

ExpandedBlockStart.gif 代码
  private   void  ptbTopLeft_MouseMove( object  sender, MouseEventArgs e)
        {
            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            
if  ( this .FormStyle  ==  FormBorderStyle.FixedDialog  ||
                
this .FormStyle  ==  FormBorderStyle.Fixed3D)
            {
                ((Control)sender).Cursor 
=  Cursors.Default;
                
if  (e.Button  ==  MouseButtons.Left  &&  e.Y  <=  SystemInformation.CaptionHeight)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   9 0 );
                }
                
return ;
            }

            
if  (e.X  <=   8   &&  e.Y  <=   8 )
            {
                ((Control)sender).Cursor 
=  Cursors.SizeNWSE;
                
if  (e.Button  ==  MouseButtons.Left) { Win32.ReleaseCapture(); Win32.SendMessage(Handle,  274 61440   +   4 0 ); }
            }
            
else   if  (e.X  <=   4 )
            {
                ((Control)sender).Cursor 
=  Cursors.SizeWE;
                
if  (e.Button  ==  MouseButtons.Left)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   1 0 );
                }
            }

            
else   if  (e.Y  <=   4 )
            {
                ((Control)sender).Cursor 
=  Cursors.SizeNS;
                
if  (e.Button  ==  MouseButtons.Left)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   3 0 );
                }
            }
            
else
            {
                ((Control)sender).Cursor 
=  Cursors.Default;
                
if  (e.Button  ==  MouseButtons.Left  &&  e.Y  <=  SystemInformation.CaptionHeight)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   9 0 );
                }
            }
        }

        
private   void  ptbTopMiddle_MouseMove( object  sender, MouseEventArgs e)
        {
            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            
if  ( this .FormStyle  ==  FormBorderStyle.FixedDialog  ||
                
this .FormStyle  ==  FormBorderStyle.Fixed3D)
            {
                ((Control)sender).Cursor 
=  Cursors.Default;
                
if  (e.Button  ==  MouseButtons.Left)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   9 0 );
                }
                
return ;
            }

            
if  (e.Y  <=   2 )
            {
                ((Control)sender).Cursor 
=  Cursors.SizeNS;
                
if  (e.Button  ==  MouseButtons.Left)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   3 0 );
                }
            }
            
else
            {
                ((Control)sender).Cursor 
=  Cursors.Default;
                
if  (e.Button  ==  MouseButtons.Left  &&  e.Y  <=  SystemInformation.CaptionHeight)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   9 0 );
                }
            }
        }

        
private   void  ptbTopRight_MouseMove( object  sender, MouseEventArgs e)
        {
            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            
if  ( this .FormStyle  ==  FormBorderStyle.Fixed3D)  return ;
            
if  ( this .FormStyle  ==  FormBorderStyle.FixedDialog)  return ;

            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            
if  (e.Y  >   8 )
            {
                ptbTopRight.Cursor 
=  Cursors.SizeWE;
                
if  (e.Button  ==  MouseButtons.Left)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   2 0 );
                }
            }
            
else   if  (e.X  >   5 )
            {
                ((Control)sender).Cursor 
=  Cursors.SizeNESW;
                
if  (e.Button  ==  MouseButtons.Left)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   5 0 );
                }
            }
            
else
            {
                ((Control)sender).Cursor 
=  Cursors.Default;
                
if  (e.Button  ==  MouseButtons.Left  &&  e.Y  <=  SystemInformation.CaptionHeight)
                {
                    Win32.ReleaseCapture();
                    Win32.SendMessage(Handle, 
274 61440   +   9 0 );
                }
            }
        }

        
private   void  Caption_MouseUp( object  sender, MouseEventArgs e)
        {
            
if  (e.Button  ==  MouseButtons.Right  &&  ((Control)sender).Cursor  ==  Cursors.Default  &&  e.Y  <=  SystemInformation.CaptionHeight)
            {
               
            }

            
if  (e.Y  <=  SystemInformation.CaptionHeight)
            {
                _captionMouseUp 
=  e.Location;
            }
            
else
            {
                _captionMouseUp 
=  Point.Empty;
            }

            
if  ( this ._skinForm  !=   null   &&   ! this ._skinForm.IsDisposed  &&   this ._skinForm.Visible)
            {
                
this ._skinForm.Close();
            }
        }

        
private   void  Caption_DouClick( object  sender, EventArgs e)
        {
            
if  (((Control)sender).Cursor  !=  Cursors.Default)  return ;
            
if  (_captionMouseUp  ==  Point.Empty)  return ;

            Win32.ReleaseCapture();
            
if  (WindowState  !=  FormWindowState.Maximized)
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(
this .Handle,  273 , Win32.SC_MAXIMIZE,  0 );

            }
            
else
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(
this .Handle,  273 , Win32.SC_RESTORE,  0 );
            }
        }

        
private   void  ptbLeft_MouseMove( object  sender, MouseEventArgs e)
        {
            
if  ( this .FormStyle  ==  FormBorderStyle.Fixed3D)  return ;
            
if  ( this .FormStyle  ==  FormBorderStyle.FixedDialog)  return ;

            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            
if  (e.Y  >   this .ptbLeft.Height  -   5 )
            {
                
this .ptbBottomLeft.Cursor  =  Cursors.SizeNESW;

            }
            
else
            {
                ptbLeft.Cursor 
=  Cursors.SizeWE;
            }

            
if  (e.Button  ==  MouseButtons.Left)
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(Handle, 
274 61440   +   7 0 );
            }
        }

        
private   void  ptbRight_MouseMove( object  sender, MouseEventArgs e)
        {

            
if  ( this .FormStyle  ==  FormBorderStyle.Fixed3D)  return ;
            
if  ( this .FormStyle  ==  FormBorderStyle.FixedDialog)  return ;

            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            
this .ptbRight.Cursor  =  Cursors.SizeWE;
            
if  (e.Button  ==  MouseButtons.Left)
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(Handle, 
274 61440   +   2 0 );
            }
        }

        
private   void  ptbBottomLeft_MouseMove( object  sender, MouseEventArgs e)
        {
            
if  ( this .FormStyle  ==  FormBorderStyle.Fixed3D)  return ;
            
if  ( this .FormStyle  ==  FormBorderStyle.FixedDialog)  return ;

            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            
this .ptbRight.Cursor  =  Cursors.SizeNESW;
            
if  (e.Button  ==  MouseButtons.Left)
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(Handle, 
274 61440   +   7 0 );
            }


        }

        
private   void  ptbBottomMiddle_MouseMove( object  sender, MouseEventArgs e)
        {
            
if  ( this .FormStyle  ==  FormBorderStyle.Fixed3D)  return ;
            
if  ( this .FormStyle  ==  FormBorderStyle.FixedDialog)  return ;

            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            ((Control)sender).Cursor 
=  Cursors.SizeNS;
            
if  (e.Button  ==  MouseButtons.Left)
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(Handle, 
274 61440   +   6 0 );
            }
        }

        
private   void  ptbBottomRight_MouseMove( object  sender, MouseEventArgs e)
        {
            
if  ( this .FormStyle  ==  FormBorderStyle.Fixed3D)  return ;
            
if  ( this .FormStyle  ==  FormBorderStyle.FixedDialog)  return ;

            
if  (WindowState  ==  FormWindowState.Maximized)  return ;

            ((Control)sender).Cursor 
=  Cursors.SizeNWSE;
            
if  (e.Button  ==  MouseButtons.Left)
            {
                Win32.ReleaseCapture();

                Win32.SendMessage(Handle, 
274 61440   +   8 0 );
            }
        }

        
private   void  btnMin_Click( object  sender, EventArgs e)
        {
            Win32.ReleaseCapture();
            Win32.SendMessage(
this .Handle,  274 , Win32.SC_MINIMIZE,  0 );
        }

        
private   void  btnMaxResore_Click( object  sender, EventArgs e)
        {
            
if  ( this .WindowState  ==  FormWindowState.Normal)
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(
this .Handle,  274 , Win32.SC_MAXIMIZE,  0 );
            }
            
else
            {
                Win32.ReleaseCapture();
                Win32.SendMessage(
this .Handle,  274 , Win32.SC_RESTORE,  0 );
            }
        }

 

强说这个窗体是很重要的一个,但是说白了这个窗体很简单,只要看代码应该都 能明白是什么意思了,大家如果有什么不懂的地方可以用源代码调试一下,或者给我留言;下周开始升级解决的一些问题,这周忙于工作,有空整合一下希望大家多多提建议

                         

转载于:https://www.cnblogs.com/jcomet/archive/2010/04/24/1719179.html

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐