PDA

View Full Version : سوال: wordwrop در listbox



ghaem-soft
دوشنبه 25 فروردین 1393, 20:10 عصر
سلام
کسی برای word wrop (توانایی چند خط نوشتن در یک item) تو list box کدی نداره
ممنون میشم اگه کمکم کنید

karem2074
سه شنبه 26 فروردین 1393, 14:36 عصر
بفرمایید دوست عزیز:



Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For x As Integer = 0 To 20
ListBox1.Items.Add(String.Format("Item {0} {1} Line 2", x,
ControlChars.NewLine))
Next
ListBox1.DrawMode = DrawMode.OwnerDrawVariable
End Sub



Private Sub ListBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ListBox1.DrawItem
Dim g As Graphics = e.Graphics
Dim s As String
Dim d As Date
Dim br As Brush = SystemBrushes.WindowText
Dim brBack As Brush
Dim rDraw As Rectangle
Dim bSelected As Boolean = CBool(e.State And
DrawItemState.Selected)

rDraw = e.Bounds
rDraw.Inflate(-1, -1)

If bSelected Then
brBack = Brushes.LightBlue
g.FillRectangle(Brushes.LightBlue, rDraw)
g.DrawRectangle(Pens.Blue, rDraw)
Else
brBack = Brushes.White
g.FillRectangle(brBack, e.Bounds)
End If

br = Nothing
brBack = Nothing
rDraw = Nothing
Try
s = ListBox1.Items.Item(e.Index).ToString
Catch
s = ""
End Try
Debug.WriteLine(String.Format("{0} {1} {2}", e.Index, s,
e.Bounds.ToString))

g.DrawString(s, ListBox1.Font, Brushes.Black,
RectangleF.op_Implicit(e.Bounds))
End Sub

Private Sub ListBox1_MeasureItem(sender As Object, e As MeasureItemEventArgs) Handles ListBox1.MeasureItem
e.ItemHeight += e.ItemHeight
End Sub

ghaem-soft
سه شنبه 26 فروردین 1393, 20:54 عصر
خیلی منون از پاسخ گویی تون

کدتون عالی بود اما چون بعضی از آیتم هام 5 خطن بعضی 1 خط مشکل منو حل نمی کنه

این کدو از سایت های خارجی پیدا کردم

ولی بلد نیستم RIGHT TO LEFT کنم ممنون میشم اگه کمکم کنید






Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

ListBox1.DrawMode = DrawMode.OwnerDrawVariable
End Sub





Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
Dim g As Graphics = e.Graphics
Dim br As SolidBrush
Dim s As String


Try
s = ListBox1.Items.Item(e.Index).ToString
Catch ex As Exception
Trace.WriteLine(ex.ToString)
s = "کلمه ای جست و جو نشده است ."
End Try


g.FillRectangle(Brushes.White, e.Bounds) 'رنگ کل لیست باکس


If CBool(e.State And DrawItemState.Selected) Then
g.FillRectangle(Brushes.LightBlue, e.Bounds)
End If


If CBool(e.State And DrawItemState.Focus) Then
g.FillRectangle(Brushes.LightBlue, e.Bounds)
End If
br = New SolidBrush(Color.Black) 'رنگ متن لیست باکس


g.DrawString(s, ListBox1.Font, br, RectangleF.op_Implicit(e.Bounds))


br.Dispose()
End Sub
Private Sub ListBox1_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ListBox1.MeasureItem
Dim g As Graphics = e.Graphics
Dim s As String


Try
s = ListBox1.Items.Item(e.Index).ToString
Catch ex As Exception
s = "کلمه ای جست و جو نشده است ."
End Try
Dim sz As SizeF = g.MeasureString(s, ListBox1.Font, ListBox1.Width - 5 - SystemInformation.VerticalScrollBarWidth)
e.ItemHeight = CInt(sz.Height) + 5
e.ItemWidth = CInt(sz.Width) + 15
End Sub

karem2074
سه شنبه 26 فروردین 1393, 21:15 عصر
زیاد روش کار کردم نشد.کلا کدش استاندارد نیست.با هر تغییری نمیشه Right To Left کرد.از این کد استفاده نکن.

مشکل از کد ListBox1.drawmode = DrawMode.OwnerDrawVariable میباشد.

ghaem-soft
سه شنبه 26 فروردین 1393, 21:32 عصر
دوست عزیز اخطار میدهد

'.Error 1 'RightToLeftLayout' is not a member of 'System.Windows.Forms.ListBox

ghaem-soft
سه شنبه 26 فروردین 1393, 21:35 عصر
با عرض پوزش می شود کدی معرفی کنید که کارایی این را داشته باشد ولی right to left شود

karem2074
سه شنبه 26 فروردین 1393, 21:41 عصر
مشکل از کد ListBox1.drawmode = DrawMode.OwnerDrawVariable میباشد.