I am trying to add a custom message to the background of a listview when there is no data to display. I have turned on the UserPaint flag via the call below which has given me exactly what I want.
SetStyle(ControlStyles.UserPaint, True)
However, this then disables all of the Item and SubItem drawing for the entire ListView. I am only assuming that with this set to true, I am now responsible for drawing all items myself (I could be wrong).
If I am correct, does anyone have a tutorial on how to custom draw list items manually, or give me some examples as I am very new to working with messages and would love to get my head around it all.
Below is my code for drawing my custom message via the OnPaint method:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim MessageFont As Font = _EmptyMessageFont
Dim MessageColour As Color = _EmptyMessageColour
Dim MessageText As String = _EmptyMessageString
If Not Me.Items.Count > 0 Then
Dim flags As TextFormatFlags
Dim rec As New Rectangle(Me.Location.X + 2, Me.Location.Y + 2, Me.Width - 4, Me.Height - 4)
flags = TextFormatFlags.HorizontalCenter Or TextFormatFlags.VerticalCenter Or TextFormatFlags.SingleLine
TextRenderer.DrawText(e.Graphics, MessageText, MessageFont, rec, MessageColour, flags)
End If
MyBase.OnPaint(e)
End Sub
Not sure how to add code in this method to handle the normal drawing of list items.