0

I have a custom listbox that inherits the WinForms ListBox class, like so.

  public class UserListBox : ListBox
  {        
     protected override void OnPaint(PaintEventArgs e)
     {
         // Omitted for brevity...
     }
  }

I add a filter on this ListBox (just like GridView control's DefaultView) but when I change the items, the OnPaint method is called regardless. I cannot call other method like remove.

I test SendMessage WM_SETREDRAW to suspend update, but that isn't working.

How can I suspend the call to the OnPaint method?

David Pine
  • 23,787
  • 10
  • 79
  • 107
nainaigu
  • 147
  • 2
  • 13

1 Answers1

0

Original

I'm not sure why you would ever want to actually do this, but it is possible. With WinForms you can actually P/Invoke into some native calls and attempt to manage things like the windows messaging loop. In all honesty, I would suggest trying to avoid doing this. What is it that you're trying to accomplish?

How can I suspend the Control.OnPaint method?

Follow this link to check out an example.

Update

According to the MSDN documentation, you're doing it correctly. Could you please provide some more source code such that I could have another look?

Community
  • 1
  • 1
David Pine
  • 23,787
  • 10
  • 79
  • 107
  • Thanks, I test the link above. `public class Win32ApiUtils { [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam); private const int WM_SETREDRAW = 11; public static void SuspendDrawing(Control parent) { SendMessage(parent.Handle, WM_SETREDRAW, false, 0); } public static void ResumeDrawing(Control parent) { SendMessage(parent.Handle, WM_SETREDRAW, true, 0); parent.Refresh(); } }` – nainaigu Feb 03 '16 at 04:25
  • i call the SuspendDrawing method for my customer listbox.but that isn't working. – nainaigu Feb 03 '16 at 04:28