Flickering in listview with ownerdraw and virtualmode

后端 未结 3 1134
我在风中等你
我在风中等你 2020-12-15 14:47

I\'m using listview control with the following parameters set:

        this.listView1.BackColor = System.Drawing.Color.Gainsboro;
        this.listView1.Colu         


        
3条回答
  •  感情败类
    2020-12-15 15:16

    I get a bunch of

    'System.Drawing.NativeMethods' is inaccessible due to its protection level
    

    and

    The type name 'NMHDR' does not exist in the type 'System.Drawing.NativeMethods' 
    

    errors. I read somewhere that I have to include user32.dll but can't figure out how to do it in this case.

    Edit: OK, I posted before even start to think. I created now my own ListView control and copied the struct from the objectListView code. It seems to work now. Here my code:

    public class Listview : ListView
    {
        private bool isInWmPaintMsg=false;
    
        [StructLayout(LayoutKind.Sequential)]
        public struct NMHDR
        {
            public IntPtr hwndFrom;
            public IntPtr idFrom;
            public int code;
        }
    
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x0F: // WM_PAINT
                    this.isInWmPaintMsg = true;
                    base.WndProc(ref m);
                    this.isInWmPaintMsg = false;
                    break;
                case 0x204E: // WM_REFLECT_NOTIFY
                    NMHDR nmhdr = (NMHDR)m.GetLParam(typeof(NMHDR));
                    if (nmhdr.code == -12)
                    { // NM_CUSTOMDRAW
                        if (this.isInWmPaintMsg)
                            base.WndProc(ref m);
                    }
                    else
                        base.WndProc(ref m);
                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }
    
    }
    

提交回复
热议问题