winforms - add icon to listbox vb.net -


Please,

How to draw an image in the listbox_DrawItem event on the left

I Already read, but it is not helping me New shape as dim shape (16, 16) image as a dim image = nothing img = My.Resources ._error e.Graphics.DrawImage (img, targetsize) e.Graphics.DrawString (lsbLog.Items (e.index) .toString (), _ e.font, mybrush, e.bounds, StringFormat.GenericDefault)

This is my current code

Edit

I have added your code with some other code, and I I get distorted text

The code in this DrawItem event

  '// Here the limit is depeding to this state (listbox item) E.Graphics.DrawRectangle (myPen, e.bounds.x + 16, e.bounds.y, _ e.bounds.Width - 16, e.Bounds.Height) (lsbLog.GetItemText (lsbLog.Items New SolidBrush (e. Using Foreword (as ForeColor) e.Graphics.DrawString b (e.Index)), E. Font, B, E. Bonds E-Graphics. Drymage (IMG, new rectangle (E. Bund. Wide - 15, E. Bounds Y, 12, 12)) Draw current item text based on '// current' // font and custom brush settings. E.Graphics.DrawString (lsbLog.Items (e.Index) .toString (), e.Font, mybrush, _ new rectangle (e.bounds.x - 20, e.bounds.Y, e.bounds.Width, e   

This is the code in the MeasureItem event

  Private sub lsbLog_MeasureItem (ByVal Sender as System Object, ByVal e System.Windows.Forms.MeasureItemEventArgs In the form of graphics lsbLog.MeasureItem dim G. Graphics = e.Graphics 'we will find the size of the string which we are about to draw about,' so that we can set ItemHeight and ItemWidth property dim size SizeF = g.MeasureString (lsbLog.Items.Item (e.Index) .toString, Me.F Ont, _ lsbLog.Width - (5 + SystemInformation.VerticalScrollBarWidth)) as e.ItemHeight = CInt (size.Height) + 5E.Itwdath = CINT (Size Wide) + 5 End Sub   

I get a lost text and image

I get a distorted image </ P> </ div> <p> <div class =

My points come in two digits Ntion:

  • Have you set as DrawMode.OwnerDrawFixed or DrawMode.OwnerDrawVariable ?

  • You draw text directly on the image. Why do you start properly that use e.bounds in DrawString instead of a rectangle? Like something like: Retarded as a new rectangle (E. Bounds, X + 16, E. Bounds, Y, _ E. Bounds, Adam - 16, E. Bounds. Use << Code>

    BTW, you should not forget to call DrawBackground and DrawFocusRectange As seen in the example.

Comments