I followed the article A "Don't show this again" checkbox for the .NET MessageBox, making a few adjustments to position the checkbox window over the existing messagebox rather than extending it to position the checkbox at the bottom as the article showed. I've ended up with a version that works perfectly but has a small cosmetic problem. The checkbox window has a white background over the grey area of the messagebox. The extension of the messagebox shown in the article puts the checkbox on a white band beneath the grey area of the messagebox, so that looked even worse.
I want to paint the background of the checkbox window the same grey (or transparent to cater for any color scheme I suppose). The windows is created with this line of code.
IntPtr buttonHwnd = CreateWindowEx(0, "button", "Don't ask me this again",
BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, x, y, width, height,
_hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
So, given I have the window handle buttonHwnd
, how do I draw its background?
I've found in How to set background color of window after I have registered it? a comment saying "When it's time to repaint your window, the system will send your wndproc a WM_ERASEBKGND message. If you don't handle it, the DefWindowProc will erase the client area with the color from the window class. But you can handle the message directly, painting whatever color (or background pattern) you like." but I can't figure out how I get a delegate that I can use to define an event handler the will allow me to do the painting. All the search results I'm finding are C++ based and show handling the event in a switch within the WndProc, which is all well and good; I just can't seem to make the jump to how I would do it in C#.
The article I worked from dates back to 2004 so there was no color difference in the messagebox to deal with; otherwise it works well. But it is pretty old so if there is a newer, better way to add a "Don't ask me again" checkbox to a message box in .NET; by all means point me to it.