!! IMPORTANT !! Problem with owner draw listbox

Y

Yair Cohen

Hello all,

i have made a class, derived from the listbox, set its property to ownerdraw
and implemnt the OnDrawItem event.

its all work, but, i have some customers that this is not working on their
computers !
it show up for a second, and disapear !
- i mean, on some computers, the listitems texts and icons are show for a
while and disapear. after this, he can click on the items but he see nothing
! its occur on XP OS with IE6.

what can I do ??

thanks a lot
yair
 
H

Herfried K. Wagner [MVP]

Yair Cohen said:
the problam is that in some computers, it works, and other its disapear.
same os (XP) and same IE(6)

Mhmmm... The code looks ok. Maybe you can replace some 'CType's to
'DirectCast's but that's not the reason for the "bug".
 
Y

Yair Cohen

first, thanks.

the problam is that in some computers, it works, and other its disapear.
same os (XP) and same IE(6)

here is my implementation code to OnDrawItem:
(u can copy this to the editor to see it clearly .....)
Protected Overrides Sub OnDrawItem(ByVal e As
System.Windows.Forms.DrawItemEventArgs)
MyBase.OnDrawItem(e)
If e.Index < 0 Then Return
Dim centerFormat As New StringFormat(StringFormatFlags.DirectionRightToLeft
Or StringFormatFlags.NoClip)
centerFormat.Alignment = StringAlignment.Near
centerFormat.LineAlignment = StringAlignment.Near
With e.Graphics
Dim textRectF As RectangleF = New RectangleF(New PointF(e.Bounds.X,
e.Bounds.Y), New SizeF(e.Bounds.Width - 34, e.Bounds.Height))
Dim imageRect As Rectangle = New Rectangle(e.Bounds.Right - 24, e.Bounds.Y +
4, 16, 16)
Dim butRect As Rectangle = New Rectangle(imageRect.X - 4, imageRect.Y - 4,
24, 24)
Select Case e.State
Case DrawItemState.Selected
'.DrawRectangle(Pens.Black, New Rectangle(e.Bounds.Left + (e.Bounds.Width -
16) / 2, e.Bounds.Y + 4, 16, 16))
If Not imlItems Is Nothing AndAlso CType(Me.Items(e.Index), HeaderData).Icon
< imlItems.Images.Count Then
..DrawImage(imlItems.Images(CType(Me.Items(e.Index), HeaderData).Icon),
imageRect)
End If
..FillRectangle(SystemBrushes.Highlight, textRectF)
..DrawString(Me.Items(e.Index).ToString, e.Font, SystemBrushes.HighlightText,
textRectF, centerFormat)
..DrawRectangle(Pens.Navy, butRect)
..DrawLine(Pens.White, butRect.Right, butRect.Y + 1, butRect.Right,
butRect.Bottom)
..DrawLine(Pens.White, butRect.X, butRect.Bottom, butRect.Right,
butRect.Bottom)
Case DrawItemState.Default, DrawItemState.None
'.DrawRectangle(Pens.Black, New Rectangle(e.Bounds.Left + (e.Bounds.Width -
16) / 2, e.Bounds.Y + 4, 16, 16))
If Not imlItems Is Nothing AndAlso CType(Me.Items(e.Index), HeaderData).Icon
< imlItems.Images.Count Then
..DrawImage(imlItems.Images(CType(Me.Items(e.Index), HeaderData).Icon),
imageRect)
End If
..FillRectangle(New SolidBrush(e.BackColor), textRectF)
..DrawString(Me.Items(e.Index).ToString, e.Font, New SolidBrush(e.ForeColor),
textRectF, centerFormat)
..DrawRectangle(New Pen(e.BackColor), butRect)
..DrawLine(New Pen(e.BackColor), butRect.Right, butRect.Y + 1, butRect.Right,
butRect.Bottom)
..DrawLine(New Pen(e.BackColor), butRect.X, butRect.Bottom, butRect.Right,
butRect.Bottom)
Case DrawItemState.HotLight
..DrawRectangle(Pens.White, butRect)
..DrawLine(Pens.Navy, butRect.Right, butRect.Y + 1, butRect.Right,
butRect.Bottom)
..DrawLine(Pens.Navy, butRect.X, butRect.Bottom, butRect.Right,
butRect.Bottom)
End Select
End With
End Sub
 
Y

Yair Cohen

thanks for the advice !
i use polymorphing a lot, and use option strict on always, so i use CTYpe a
lot, where directcast can improve my performance, Thanks !

yair
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top