C#仿QQ皮肤-CustomScrollbar 控件实现

 阅读全文:http://www.sufeinet.com/thread-2087-1-1.html

导读部分
-------------------------------------------------------------------------------------------------------------
C#仿QQ皮肤-实现原理系列文章导航 最新版源码下载

http://www.sufeinet.com/thread-2-1-1.html

       

大家还是先来看看效果吧


                    

下面我们一起来看看是怎么样实现的


1.这控件还没有真正的完成,大家也只能试用一下了,效果基本是这样的,上面的上下箭头和中间的滚动的图片都是动态要吧调整的,具体的方法大家自己参考 一下源代码吧,如果有更新,或是真正写在控件里的时候我会在皮肤的新版本中给出,这里我们先来看看控件的基本实现吧,做过自定义滚动条的朋友应该都 知道 什么是Windows消息,.net没有提共控件的直接Scroll,我们只能通过拦截Windows消息来处理了,和处理APIHook来解决问题了,Windows消息一般要处理这样几个VSCROLL,WM_HITTEST,WM_NCMOUSEMOVE

在这里我多说几句,在处理滚动条的时候一般都 要处理这样几个方法

1.第一个是Value值

      这里有一段参考代码可以分享一下

代码
public int Value
        {
            
get { return moValue; }
            
set
            {
                moValue 
= value;

                
int nTrackHeight = (this.Height - (UpArrowImage.Height + DownArrowImage.Height));
                
float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight;
                
int nThumbHeight = (int)fThumbHeight;

                
if (nThumbHeight > nTrackHeight)
                {
                    nThumbHeight 
= nTrackHeight;
                    fThumbHeight 
= nTrackHeight;
                }
                
if (nThumbHeight < 56)
                {
                    nThumbHeight 
= 56;
                    fThumbHeight 
= 56;
                }

                
//figure out value
                int nPixelRange = nTrackHeight - nThumbHeight;
                
int nRealRange = (Maximum - Minimum) - LargeChange;
                
float fPerc = 0.0f;
                
if (nRealRange != 0)
                {
                    fPerc 
= (float)moValue / (float)nRealRange;

                }

                
float fTop = fPerc * nPixelRange;
                moThumbTop 
= (int)fTop;


                Invalidate();
            }
        }

其它的跟这个基本上差不多,都 是先画个自己的滚动条,然后通过Api把系统的隐藏,把自己的加上,并且让他们产生连动;

用到的Api介绍一下

 阅读全文:http://www.sufeinet.com/thread-2087-1-1.html

原文地址:https://www.cnblogs.com/sufei/p/1776182.html