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 606183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:13:38+00:00 2026-05-13T17:13:38+00:00

I want some way to make a given word bold(the first two characters of

  • 0

I want some way to make a given word bold(the first two characters of each item in a listbox), and nothing else, something like this:

01 car
02 house
03 market

As for these three, being items in a listbox control, ALWAYS the first two characters, the rest should not be bold.

Is there any practical way for doing so ?

Data:

  • Visual Studio 2008
  • .NET 3.5

request:

    private void lstMaster_DrawItem(object sender, DrawItemEventArgs e)
    {
//TEST
        e.DrawBackground();
        Brush myBrush = Brushes.Black;
        Pen pen = new Pen(myBrush);
        e.Graphics.DrawRectangle(pen, 0, 0, 10, 10); //BREAKPOINT HERE

        e.Graphics.DrawString("aaa" + lstMaster.Items[e.Index].ToString(),
e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);

        e.DrawFocusRectangle();

    }

It just keept the same, no rectangle, no “AAA”, or square no breakpoint reached…

  • 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-13T17:13:39+00:00Added an answer on May 13, 2026 at 5:13 pm

    It is possible, You will need to use the listbox’s DrawItem event and from there you can draw your items however you would like to:

    DrawItem event on MSDN

    Here is an example that draws each item with different color:

    private void ListBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
      // Draw the background of the ListBox control for each item.
      e.DrawBackground();
      // Define the default color of the brush as black.
      Brush myBrush = Brushes.Black;
    
      // Determine the color of the brush to draw each item based 
      // on the index of the item to draw.
      switch (e.Index)
      {
          case 0:
              myBrush = Brushes.Red;
              break;
          case 1:
              myBrush = Brushes.Orange;
              break;
          case 2:
              myBrush = Brushes.Purple;
              break;
      }
    
      // Draw the current item text based on the current Font 
      // and the custom brush settings.
      e.Graphics.DrawString(ListBox1.Items[e.Index].ToString(), 
        e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
      // If the ListBox has focus, draw a focus rectangle around the selected item.
      e.DrawFocusRectangle();
     }
    

    According to the documentation you will also need to change the DrawMode property of the listbox in order the fire the event:

    This event is used by an owner-drawn ListBox. The event is only raised when the DrawMode property is set to DrawMode.OwnerDrawFixed or DrawMode.OwnerDrawVariable. You can use this event to perform the tasks needed to draw items in the ListBox.

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

Sidebar

Related Questions

I have 3 Linux machines, and want some way to keep the dotfiles in
Is there some way to run 2 threads at the same time? I want
I want to show HTML content inside Flash. Is there some way to do
I want some of the items to be bold depending on a property of
I want some like this: How make it ideologically correct?
Here I want to make some modificatins for my setting. I want response from
What's the simplest way, given a string: NSString *str = @Some really really long
I want some slightly 'dynamic' XML source files. I want some of the element
I want some particular urls like springer.com to automatically convert to springer.com.proxy1.mycollege.edu. The second
I want some examples of C preprocessor directives, such as: #define pi 3.14 #define

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.