原文地址:http://www.cckan.net/thread-1949-1-1.html 可提供源码下载
导读部分
-------------------------------------------------------------------------------------------------------------
C#仿QQ皮肤-实现原理系列文章导航 最新版源码下载
http://www.cckan.net/thread-2-1-1.html
最过忙坏了,呵呵,费话不多说开始今天的活吧,EnterUserControl是为EnterFrom1这个用户控件服务的,这是一个用户控件,本身没有意义主要是子类实现,我们先来看看实现的效果吧
这里就是实现 的效果图片,
构造器实现


{
this .SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true );
InitializeComponent();
this .Controls.Remove( this .pnlRight);
this .Controls.Remove( this .pnlLeft);
this .Controls.Remove( this .pnlBackGroup);
}
这里就不多说了和之前的实现基本没有任何分别 ,下面是重写的WndProc方法


{
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 ;
}
}
在这之后我们再重写一下OnLoad事件就成功一半了


{
this .Controls.Add( this .pnlRight);
this .Controls.Add( this .pnlLeft);
this .Controls.Add( this .pnlBackGroup);
if ( ! DesignMode)
{
this .Hide();
}
base .OnLoad(e);
Win32.SetWindowLong( this .Handle, - 16 ,Win32.GetWindowLong( this .Handle, - 16 ) - Win32.WS_MAXIMIZEBOX );
this .Show();
}
在加载时我添加这三个Panel
this .Controls.Add( this .pnlLeft);
this .Controls.Add( this .pnlBackGroup);
为了移动是方便我们加上这两个事件
1.Caption_MouseMove事件


{
((Control)sender).Cursor = Cursors.Default;
if (e.Button == MouseButtons.Left)
{
Win32.ReleaseCapture();
Win32.SendMessage(Handle, 274 , 61440 + 9 , 0 );
}
}
2.caption_MouseUp事件


{
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 );
}
}
最的我们重写一下Text属性


{
get
{
return base .Text;
}
set
{
base .Text = value;
}
}
这个相对来说比较简单一些了
我就不多说什么了,大家把代码调试一下就明白了。感谢大家支持