I tried to do what you asked, but when you extend on the ListView
Control the OnPaint() method cannot be overridden because the CF
doesn't not call OnPaint() on the ListView. It is called lower down
in the OS.
Anyway, I have managed to use a class that catches Windows Messages
(WM_Paint) on the ListView Control and then calls a method in my
ListViewExtender class (this is through a delegate). Now I can get the
ListView to display the background image perfectly. But the
ListViewItems that I add to the ListViewExtender instance do not get
displayed. Is this because I have used the DrawImage() method which
draws the images on top of the ListView items? Or is it a case that I
must also re-draw the ListViewItems?
The following code is what I have in my ListViewExtender Class...
// Constructor that registers this Control to be hooked.
public BGListView()
{
// Messages required to override
// in this control's window procedure.
WndProcHooker.HookWndProc(this,
new WndProcHooker.WndProcCallback(this.WM_Paint_Handler),
Win32.WM_PAINT);
}
// The callback called when the window receives a WM_PAINT message.
// We draw the button in the appropriate state.
// hwnd - The handle to the window that received the message
// wParam - Indicates whether various virtual keys are down.
// lParam - The coordinates of the cursor
// handled - Set to true if we don't want to pass this message on to
the original window procedure
// Returns zero if we process this message.
int WM_Paint_Handler(
IntPtr hwnd, uint msg, uint wParam, int lParam, ref bool handled)
{
Win32.PAINTSTRUCT ps = new Win32.PAINTSTRUCT();
Graphics gr = Graphics.FromHdc(Win32.BeginPaint(hwnd, ref
ps));
//DrawButton(gr, this.Capture &&
//
(this.ClientRectangle.Contains(lastCursorCoordinates)));
DrawListView(gr);
gr.Dispose();
Win32.EndPaint(hwnd, ref ps);
handled = true;
return 0;
}
// Gets a Graphics object for the provided window handle and then calls
DrawButton(Graphics, bool).
// hwnd - The handle to the window to draw as a button
// pressed - If true, the button is draw in the depressed state
void DrawListView(Graphics gr)
{
//DrawButton(gr, pressed);
gr.DrawImage(m_BackgroundImage,
this.ClientRectangle,
new Rectangle(0, 0, m_BackgroundImage.Width,
m_BackgroundImage.Height),
GraphicsUnit.Pixel);
}
I have used the following classes (supplied by MS) to catch and handle
the Windows Messages (WM_Paint) for the ListView Control...
http://msdn2.microsoft.com/en-US/library/ms229658.aspx
http://msdn2.microsoft.com/en-US/library/ms229683.aspx
Thanks in advance if your able to help me out with this.