Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4067524
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:15:37+00:00 2026-05-20T16:15:37+00:00

please, how do i draw image in listbox_DrawItem event by the left side i

  • 0

please,

how do i draw image in listbox_DrawItem event by the left side

i already read throught this code, buts its not helping me

Dim targetsize As New Size(16, 16)
Dim img As 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 added your code with some other code, and i get a garbled text

this is part of the code in the DrawItem event

'//Here it draws the border depeding on it's state (the listbox item)
        e.Graphics.DrawRectangle(myPen, e.Bounds.X + 16, e.Bounds.Y, _
                                 e.Bounds.Width - 16, e.Bounds.Height)
        Using b As New SolidBrush(e.ForeColor)
            e.Graphics.DrawString(lsbLog.GetItemText(lsbLog.Items(e.Index)), e.Font, b, e.Bounds)
        End Using
        e.Graphics.DrawImage(img, New Rectangle(e.Bounds.Width - 15, e.Bounds.Y, 12, 12))
        '// Draw the current item text based on the current 
        '// Font and the 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.Bounds.Height), _
                               StringFormat.GenericDefault)

This is the code in the MeasureItem event

 Private Sub lsbLog_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles lsbLog.MeasureItem
        Dim g As Graphics = e.Graphics
        'We will get the size of the string which we are about to draw,
        'so that we could set the ItemHeight and ItemWidth property
        Dim size As SizeF = g.MeasureString(lsbLog.Items.Item(e.Index).ToString, Me.Font, _
        lsbLog.Width - (5 + SystemInformation.VerticalScrollBarWidth))
        e.ItemHeight = CInt(size.Height) + 5
        e.ItemWidth = CInt(size.Width) + 5
    End Sub

I get a garbeled text and image

I get a garbled image

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:15:38+00:00Added an answer on May 20, 2026 at 4:15 pm

    Two points come to my attention:

    • Did you set the DrawMode to DrawMode.OwnerDrawFixed or DrawMode.OwnerDrawVariable, as stated in the documentation?

    • You seem to be drawing the text directly over the image. Why do you use e.Bounds in DrawString instead of a rectangle that starts a little bit to the right? E.g. something like:

      Dim rect As New Rectangle(e.Bounds.X + 16, e.Bounds.Y, _
                                e.Bounds.Width - 16, e.Bounds.Height)
      ' use rect instead of e.Bounds in DrawString
      

    BTW, you shouldn’t forget to call DrawBackground and DrawFocusRectange as seen in the example in the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my new code but it does not render external image, please help.
Please i need help, this code below works fine on my localhost, php5.3+ but
please help me arrange these 3 buttons horizontally like this photoshopped image: Please take
This is the code I have, it actually works, not perfectly but it does,
please help me to make this code parallel using openmp this code is run
To flip an image around the center i am using this piece of code:
I want to read an image into MATLAB, draw a rectangle on it, and
I use this code to draw a line in quartz2d CGPoint currentPoint = CGPointMake(rascalImage.center.x,
Could you please share some code (any language) on how draw textured line (that
Please note that this question is about CGLayer (which you typically use to draw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.