zoukankan      html  css  js  c++  java
  • 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);
            }
        }

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

  • 相关阅读:
    mysql-索引与优化
    sql优化
    PHP高并发
    MySQL 数据类型
    ERROR 2013 (HY000): Lost connection to MySQL server
    建模各阶段以及相关UML构造笔记
    Code Complete 笔记—— 第二章 用隐喻来更充分理解软件开发
    Code Complete 笔记—— 第一章
    Laravel使用笔记 —— migration
    本地xdebug调试搭建 Laravel+homestead+phpstorm
  • 原文地址:https://www.cnblogs.com/crwy/p/9332256.html
Copyright © 2011-2022 走看看