Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. how can do bold some items of comboBox

how can do bold some items of comboBox

Scheduled Pinned Locked Moved C#
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sikandarhayat
    wrote on last edited by
    #1

    Dear programmers is there any way that some item of combobox can be bold and remaining will be regular. if it is then plz tell me how.. thanks in advance.

    sikandar

    C 1 Reply Last reply
    0
    • S sikandarhayat

      Dear programmers is there any way that some item of combobox can be bold and remaining will be regular. if it is then plz tell me how.. thanks in advance.

      sikandar

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You need to make it owner drawn and render the text yourself.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      S 1 Reply Last reply
      0
      • C Christian Graus

        You need to make it owner drawn and render the text yourself.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        S Offline
        S Offline
        sikandarhayat
        wrote on last edited by
        #3

        thanks for response i don know how can i render the text can u plz give descpriction thanks

        sikandar

        J 1 Reply Last reply
        0
        • S sikandarhayat

          thanks for response i don know how can i render the text can u plz give descpriction thanks

          sikandar

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          Its quite easy to make an Owner Drawn control. Basically, you are telling a control that you will write the code to draw each item in a control. In the case of a combo box, each item is an item in the drop-down portion. To do it, follow these steps 1) Drag a combo box to your form 2) In the properties window change its DrawMode property to OwnerDrawnFixed 3) Change to the events and double click the DrawItem event 4) Switch to code view and you should have this private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { } 5) Write your code in there, for example I used the following code to alternate bold and nomal items private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if((e.Index%2)==0) { e.Graphics.DrawString(this.comboBox1.Items[e.Index].ToString(),e.Font,Brushes.Black,e.Bounds,StringFormat.GenericDefault); } else { Font boldFont = new Font(e.Font,FontStyle.Bold); e.Graphics.DrawString(this.comboBox1.Items[e.Index].ToString(),boldFont,Brushes.Black,e.Bounds,StringFormat.GenericDefault); } }

          --- How to get answers to your questions[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups