ListView鼠标框选实现蓝色蒙板

此问题留心已久,今日方悉心求之,记录心得。

ListView控件,不论Delphi中的TListView还是c#中的ListView,在开启其MultiSelect属性时,鼠标框选只是显示框张,如下图示:

 

相信如系统资源管理器那样,框选以蓝色蒙板显示,视觉效果要好上许多。里外翻阅,发现与LVS_EX_DOUBLEBUFFER标记有关。

根据此线索,改造之。

 

1、Delphi之TListView

type
  TListView = class(ComCtrls.TListView)
  private
   procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
  protected
    procedure CreateWnd; override;
  end;

...

uses
CommCtrl;
{ TListView } procedure TListView.CreateWnd; var Styles: DWORD; begin inherited CreateWnd; if CheckWin32Version(5, 1) then begin Styles := ListView_GetExtendedListViewStyle(WindowHandle); Styles := Styles or LVS_EX_DOUBLEBUFFER; ListView_SetExtendedListViewStyle(WindowHandle, Styles); end; end; procedure TListView.WMEraseBkgnd(var Message: TWMEraseBkgnd); begin DefaultHandler(Message); end;

 

2、c#之ListView

    class ListViewEx : System.Windows.Forms.ListView
    {
        public ListViewEx()
        {
            // 开启双缓冲
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
            UpdateStyles();

            // Enable the OnNotifyMessage event so we get a chance to filter out 
            // Windows messages before they get to the form's WndProc
            this.SetStyle(ControlStyles.EnableNotifyMessage, true);
        }

        protected override void OnNotifyMessage(Message m)
        {
            //Filter out the WM_ERASEBKGND message
            if (m.Msg != 0x14)
                base.OnNotifyMessage(m);
        }
    }

 

验证实现所需,效果如下图:

转载于:https://www.cnblogs.com/crwy/p/9332256.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值