Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Change listbox row thickness

Posted on 2013-01-25
Medium Priority
Last Modified: 2013-01-28
Is there a way to change the thickness of the lines that show in a listbox control?  I want to make them lighter.

Question by:esemmoc
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Expert Comment

by:Naman Goel
ID: 38821887
You can use drawitem event for this, set DrawMode property to OwnerDrawFixed and handle DrawItem event.

using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication4
    public partial class Form1 : Form
        private ListBox listBox1;
        public Form1()

        private void InitializeComponent()
            this.listBox1 = new System.Windows.Forms.ListBox();
            // listBox1
            this.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Items.AddRange(new object[] {
            this.listBox1.Location = new System.Drawing.Point(42, 12);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(173, 199);
            this.listBox1.TabIndex = 0;
            this.listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
            // Form1
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Name = "Form1";


        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
            e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), listBox1.Font, new SolidBrush(listBox1.ForeColor), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width -2 , e.Bounds.Height - 2));

Open in new window

LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 38822094
LVL 10

Expert Comment

by:Monica P
ID: 38825888
try it out whether this inline css helps u

<select style="width: 100px;"></select>

Open in new window

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 38827827
I am using and tried the below solution but it doesn't seem to change the display.

by: Medo3337Posted on 2013-01-26 at 05:48:08ID: 38822094
Check out this link:

e.Graphics.DrawRectangle(myPen, e.Bounds.X, e.Bounds.Y, e.Bounds.Width-1,e.Bounds.Height)

My code:

e.Graphics.DrawRectangle(myPen, e.Bounds.X, e.Bounds.Y, e.Bounds.Width-1,e.Bounds.Height)

 e.Graphics.DrawString(lstShipping.Items(e.Index).ToString, txtfnt, txtBrush, R)

On further thought, is it possible to remove the lines completely, e.g. go from a "ruled" listbox to an "unruled" listbox?
LVL 13

Accepted Solution

Naman Goel earned 1400 total points
ID: 38827843
yeah, use DrawItem event to do whatever you want it is very simple GDI painting, you can achieve whatever you want.

Author Closing Comment

ID: 38827997
Great.  I used e.Graphics.DrawRectangle(Pens.LightGray, e.Bounds) to "soften" the lines displayed.   To completely remove the lines (an affect I tried but didn't like) just make the "Pens.xxxx" the same color as the color in the e.Graphics.FillRectangle statement.


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question