I am try to Inherits a Listbox control to change StringFormatFlags direction. All is OK, but when I change the font size of Listbox control it dose not draw item properly. How to fix this issue. I am stuck with this problem from many days.
PHP Code:
Public Class UrduListBox
Inherits ListBox
Public Sub New()
Me.DrawMode = DrawMode.OwnerDrawVariable
AddHandler Me.DrawItem, AddressOf Draw_DrawItem
End Sub
Public Sub Draw_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)
Try
Dim sf As New StringFormat()
If sender.RightToLeft = Windows.Forms.RightToLeft.Yes Then
sf.FormatFlags = StringFormatFlags.DirectionRightToLeft
End If
Dim br As New SolidBrush(sender.ForeColor)
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
e.DrawBackground()
br = Brushes.White
Else
e.Graphics.FillRectangle(New SolidBrush(e.BackColor), e.Bounds)
br = Brushes.Black
End If
Using fnt As New Font(sender.Font.Name.ToString(), sender.Font.Size.ToString(), FontStyle.Regular, GraphicsUnit.Point)
e.Graphics.DrawString(sender.Items(e.Index).ToString(), fnt, br, e.Bounds, sf)
End Using
Catch ex As Exception
End Try
End Sub