Solved

Change listbox row thickness

Posted on 2013-01-25
6
400 Views
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.

Thanks.
0
Comment
Question by:esemmoc
6 Comments
 
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()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.SuspendLayout();
            // 
            // listBox1
            // 
            this.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Items.AddRange(new object[] {
            "abcd",
            "XYZL",
            "LMNO",
            "IPQR"});
            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.Controls.Add(this.listBox1);
            this.Name = "Form1";
            this.ResumeLayout(false);

        }

        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            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));
            e.DrawFocusRectangle();
        }
    }
}

Open in new window

0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 38822094
0
 
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

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:esemmoc
ID: 38827827
I am using vb.net 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:
http://stackoverflow.com/questions/5663735/draw-listbox-item-properly-vb-net-2005

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?
0
 
LVL 13

Accepted Solution

by:
Naman Goel earned 350 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.
0
 

Author Closing Comment

by:esemmoc
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.

Thanks.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now