T
Try Guy
I'm trying to learn this ownerdrawing thing and I have tested a few things
with a listbox and drawing the items myself..
Here' my small Form Load
'-----------------------------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Counter As Integer
For Counter = 1 To 5
Dim myItem As New ListViewItem("Item")
myItem.SubItems.Add("text")
ListBox1.Items.Add(myItem)
Next
End Sub
'-----------------------------------------
I have this in my DrawItem Sub
'------------------------------------------------
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
Dim MyCaption As String = "Item " & e.Index
Dim MyBrush As System.Drawing.Brush = System.Drawing.Brushes.Black
Dim MyFont As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel)
Dim MySizeF As SizeF = e.Graphics.MeasureString(MyCaption, MyFont)
e.Graphics.DrawString(MyCaption, MyFont, MyBrush, e.Bounds.X + 20,
e.Bounds.Y)
End Sub
'--------------------------------------------------------------------------
Since I want to add the text "text" in form load.. wouldn't it be good if
that text actually did show up in the Itembox and not the text "Item" that I
use in theDrawItem... now.. I understand of course that it's the DrawItem
that does all this stuff.. but... what if I, in DrawItem, does'nt have
access to the text that I want to add with an item... How does all this
work?
In the e areguments I have'nt found anything that will give me the "text"
text... from what triggered the DrawItem..
And also.. what about subitems hwo do they get in there... if I woudl to
draw them myself.. ?
/Try Guy
with a listbox and drawing the items myself..
Here' my small Form Load
'-----------------------------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Counter As Integer
For Counter = 1 To 5
Dim myItem As New ListViewItem("Item")
myItem.SubItems.Add("text")
ListBox1.Items.Add(myItem)
Next
End Sub
'-----------------------------------------
I have this in my DrawItem Sub
'------------------------------------------------
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
Dim MyCaption As String = "Item " & e.Index
Dim MyBrush As System.Drawing.Brush = System.Drawing.Brushes.Black
Dim MyFont As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel)
Dim MySizeF As SizeF = e.Graphics.MeasureString(MyCaption, MyFont)
e.Graphics.DrawString(MyCaption, MyFont, MyBrush, e.Bounds.X + 20,
e.Bounds.Y)
End Sub
'--------------------------------------------------------------------------
Since I want to add the text "text" in form load.. wouldn't it be good if
that text actually did show up in the Itembox and not the text "Item" that I
use in theDrawItem... now.. I understand of course that it's the DrawItem
that does all this stuff.. but... what if I, in DrawItem, does'nt have
access to the text that I want to add with an item... How does all this
work?
In the e areguments I have'nt found anything that will give me the "text"
text... from what triggered the DrawItem..
And also.. what about subitems hwo do they get in there... if I woudl to
draw them myself.. ?
/Try Guy