重绘Progressbar

重绘progressbar
using   System;
using   System.Collections.Generic;
using   System.Text;
using   System.ComponentModel;  
using   System.Drawing;
using   System.Windows.Forms;

namespace   csPublish
{
        [ToolboxItem(true)]  
        class   textProgressBar   :   System.Windows.Forms.ProgressBar
        {
                [System.Runtime.InteropServices.DllImport( "user32.dll ")]
                static   extern   IntPtr   GetWindowDC(IntPtr   hWnd);
                [System.Runtime.InteropServices.DllImport( "user32.dll ")]
                static   extern   int   ReleaseDC(IntPtr   hWnd,   IntPtr   hDC);  

                private   System.Drawing.Color   _TextColor   =   System.Drawing.Color.Black;
                private   System.Drawing.Font   _TextFont   =   new   System.Drawing.Font( "SimSun ",   9);
               
                public   System.Drawing.Color   TextColor
                {
                        get   {   return   _TextColor;   }
                        set   {   _TextColor   =   value;   this.Invalidate();   }
                }

                public   System.Drawing.Font   TextFont
                {
                        get   {   return   _TextFont;   }
                        set   {   _TextFont   =   value;   this.Invalidate();   }
                }

                protected   override   void   WndProc(ref   Message   m)
                {
                        base.WndProc(ref   m);
                        if   (m.Msg   ==   0xf   ||   m.Msg   ==   0x133)
                        {
                                //拦截系统消息,获得当前控件进程以便重绘。  
                                //一些控件(如TextBox、Button等)是由系统进程绘制,重载OnPaint方法将不起作用.  
                                //所有这里并没有使用重载OnPaint方法绘制TextBox边框。  
                                //  
                                //MSDN:重写   OnPaint   将禁止修改所有控件的外观。  
                                //那些由   Windows   完成其所有绘图的控件(例如   Textbox)从不调用它们的   OnPaint   方法,  
                                //因此将永远不会使用自定义代码。请参见您要修改的特定控件的文档,  
                                //查看   OnPaint   方法是否可用。如果某个控件未将   OnPaint   作为成员方法列出,  
                                //则您无法通过重写此方法改变其外观。  
                                //  
                                //MSDN:要了解可用的   Message.Msg、Message.LParam   和   Message.WParam   值,  
                                //请参考位于   MSDN   Library   中的   Platform   SDK   文档参考。可在   Platform   SDK(“Core   SDK”一节)  
                                //下载中包含的   windows.h   头文件中找到实际常数值,该文件也可在   MSDN   上找到。  
                                IntPtr   hDC   =   GetWindowDC(m.HWnd);
                                if   (hDC.ToInt32()   ==   0)
                                {
                                        return;
                                }

                                //base.OnPaint(e);
                                System.Drawing.Graphics   g   =   Graphics.FromHdc(hDC);
                                SolidBrush   brush   =   new   SolidBrush(_TextColor);
                                string   s   =   this.Minimum   +   "/ "   +   this.Maximum;
                                SizeF   size   =   g.MeasureString(s,   _TextFont);
                                float   x   =   (this.Width   -   size.Width)   /   2;
                                float   y   =   (this.Height   -   size.Height)   /   2;
                                g.DrawString(s,   _TextFont,   brush,   x,   y);
                                //返回结果  
                                m.Result   =   IntPtr.Zero;
                                //释放  
                                ReleaseDC(m.HWnd,   hDC);
                        }
                }  
        }
http://blog.163.com/liguisheng_002/blog/static/2689512200910943259535/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码者人生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值