栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

更新单个ListViewItem的文本时,如何防止ListView中出现闪烁?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

更新单个ListViewItem的文本时,如何防止ListView中出现闪烁?

要结束这个问题,这里是一个帮助程序类,当为表单中的每个ListView或任何其他ListView的派生控件加载表单时,应调用该类。感谢“ Brian
Gillespie”提供的解决方案。

public enum ListViewExtendedStyles{    /// <summary>    /// LVS_EX_GRIDLINES    /// </summary>    GridLines = 0x00000001,    /// <summary>    /// LVS_EX_SUBITEMIMAGES    /// </summary>    SubItemImages = 0x00000002,    /// <summary>    /// LVS_EX_CHECKBOXES    /// </summary>    CheckBoxes = 0x00000004,    /// <summary>    /// LVS_EX_TRACKSELECT    /// </summary>    TrackSelect = 0x00000008,    /// <summary>    /// LVS_EX_HEADERDRAGDROP    /// </summary>    HeaderDragDrop = 0x00000010,    /// <summary>    /// LVS_EX_FULLROWSELECT    /// </summary>    FullRowSelect = 0x00000020,    /// <summary>    /// LVS_EX_onECLICKACTIVATE    /// </summary>    oneClickActivate = 0x00000040,    /// <summary>    /// LVS_EX_TWOCLICKACTIVATE    /// </summary>    TwoClickActivate = 0x00000080,    /// <summary>    /// LVS_EX_FLATSB    /// </summary>    FlatsB = 0x00000100,    /// <summary>    /// LVS_EX_REGIonAL    /// </summary>    Regional = 0x00000200,    /// <summary>    /// LVS_EX_INFOTIP    /// </summary>    InfoTip = 0x00000400,    /// <summary>    /// LVS_EX_UNDERLINEHOT    /// </summary>    UnderlineHot = 0x00000800,    /// <summary>    /// LVS_EX_UNDERLINECOLD    /// </summary>    UnderlineCold = 0x00001000,    /// <summary>    /// LVS_EX_MULTIWORKAREAS    /// </summary>    MultilWorkAreas = 0x00002000,    /// <summary>    /// LVS_EX_LABELTIP    /// </summary>    LabelTip = 0x00004000,    /// <summary>    /// LVS_EX_BORDERSELECT    /// </summary>    BorderSelect = 0x00008000,    /// <summary>    /// LVS_EX_DOUBLEBUFFER    /// </summary>    DoubleBuffer = 0x00010000,    /// <summary>    /// LVS_EX_HIDELABELS    /// </summary>    HideLabels = 0x00020000,    /// <summary>    /// LVS_EX_SINGLEROW    /// </summary>    SingleRow = 0x00040000,    /// <summary>    /// LVS_EX_SNAPTOGRID    /// </summary>    SnapToGrid = 0x00080000,    /// <summary>    /// LVS_EX_SIMPLESELECT    /// </summary>    SimpleSelect = 0x00100000}public enum ListViewMessages{    First = 0x1000,    SetExtendedStyle = (First + 54),    GetExtendedStyle = (First + 55),}/// <summary>/// Contains helper methods to change extended styles on ListView, including enabling double buffering./// based on Giovanni Montrone's article on <see cref="http://www.preproject.com/KB/list/listviewxp.aspx"/>/// </summary>public class ListViewHelper{    private ListViewHelper()    {    }    [Dllimport("user32.dll", CharSet = CharSet.Auto)]    private static extern int SendMessage(IntPtr handle, int messg, int wparam, int lparam);    public static void SetExtendedStyle(Control control, ListViewExtendedStyles exStyle)    {        ListViewExtendedStyles styles;        styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);        styles |= exStyle;        SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);    }    public static void EnableDoubleBuffer(Control control)    {        ListViewExtendedStyles styles;        // read current style        styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);        // enable double buffer and border select        styles |= ListViewExtendedStyles.DoubleBuffer | ListViewExtendedStyles.BorderSelect;        // write new style        SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);    }    public static void DisableDoubleBuffer(Control control)    {        ListViewExtendedStyles styles;        // read current style        styles = (ListViewExtendedStyles)SendMessage(control.Handle, (int)ListViewMessages.GetExtendedStyle, 0, 0);        // disable double buffer and border select        styles -= styles & ListViewExtendedStyles.DoubleBuffer;        styles -= styles & ListViewExtendedStyles.BorderSelect;        // write new style        SendMessage(control.Handle, (int)ListViewMessages.SetExtendedStyle, 0, (int)styles);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/514732.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号