.: Home :: Contact Us :.  
  



Hans Dietrich Software

free and licensed software

   

XListBoxCS

Listboxes are still useful for many things. I use them frequently when I need to log something, to keep real-time track of processes. Usually, logging means flagging some exception or unusual event, so it is nice to be able to use colors to draw user's attention to these items. XListBoxCS does this and more, with only two files added to your Windows Forms project.

Features

screenshot Custom text and background colors for items.
screenshot Optional bold text for items.
screenshot Drop-in replacement for .Net listbox - you don't need to use the Designer to begin using XListBoxCS.
screenshot Optional printf-style formatting.
screenshot Optional auto-scroll property keeps last item in view.
screenshot Internal context menu lets you copy items from XListBoxCS.
screenshot Custom OnPaint handler eliminates flicker seen in standard listbox.
screenshot Written from the ground up for VS2008 Windows Forms applications.

XListBoxCS Demo

The download includes demo project that demonstrates XListBoxCS features:

screenshot

Here is the code that displays the above strings:

private void InitListbox()
{
    string text = textBox1.Text;
    listBox1.Add("0 " + text);
    listBox1.Add("%d %s", ++count, text);
    listBox1.Add(Color.FromName("Black"), Color.FromName("White"), "2 " + text);
    ++count;
    listBox1.Add(Color.FromName("Black"), Color.FromName("White"), "%d %s", ++count, text);
    listBox1.Add(Color.FromName("Black"), Color.FromName("White"), true, "%d %s", ++count, text);
    listBox1.Add(Color.FromName("Red"), Color.FromName("White"), "%d %s", ++count, text);
    listBox1.Add(Color.FromName("DodgerBlue"), Color.FromName("White"), "%d %s", ++count, text);
    listBox1.Add(Color.FromName("ForestGreen"), Color.FromName("White"), "%d %s", ++count, text);
    listBox1.Add(Color.FromName("Lime"), Color.FromName("Black"), "%d %s", ++count, text);
    listBox1.Add(Color.FromName("White"), Color.FromName("Red"), "%d %s", ++count, text);
    listBox1.Add(Color.FromName("Black"), Color.FromName("Yellow"), "%d %s", ++count, text);
}

XListBoxCS API

The usual way to add items to a listbox is by accessing the ListBox.Items member. This will work with XListBoxCS, but you will not be able to specify colors. To access all the features of XListBoxCS, use the methods listed below:


Methods
  public int Add() Adds a blank line.
  public int Add(Color forecolor, Color backcolor, bool bold, string format, params object[] parameters) Adds an item with colors and bold state using printf formatting.
  public int Add(Color forecolor, Color backcolor, object item) Adds an item with colors.
  public int Add(Color forecolor, Color backcolor, string format, params object[] parameters) Adds an item with colors using printf formatting.
  public int Add(object item) Adds an item with current listbox colors.
  public int Add(string format, params object[] parameters) Adds an item with current listbox colors using printf formatting.
  public void Clear() Clears listbox.
  public Color GetBackColor(int index) Get background color of item.
  public bool GetBold(int index) Get bold state of item.
  public Color GetForeColor(int index) Get text color of item.
  public int IndexOf(object item) Get index of item.
  public void Insert(int index, object o) Insert item with current listbox colors.
  public void Insert(int index, Color forecolor, Color backcolor, bool bold, string format, params object[] parameters) Inserts item with colors and bold state using printf formatting.
  public void Remove(object item) Removes item.
  public void RemoveAt(int index) Removes item at index.

Properties
  public bool AutoScroll { get; set; } Gets/Sets autoscroll property.
  public int Count Gets count of listbox items.

Sort Not Supported

The current implementation disables sorting, so that the internal colors and bold lists will be in sync with the listbox strings. Please let us know if you have a need for sorted listboxes.

How To Use

To integrate XListBoxCS into your project, follow these steps:

  1. Add the two files XListBoxCS.cs and HDTools.cs to your project:

    screenshot

  2. If you do not already have a listbox, drag a listbox from the toolbox and drop it on your form.
  3. in Form1.Designer.cs (or whatever your form is called), replace two lines as follows (using the name you have given the listbox):

        Replace
           this.listBox1 = new System.Windows.Forms.ListBox();
        with this line:
           this.listBox1 = new XLISTBOXCS.XListBoxCS();

        Replace
           private System.Windows.Forms.ListBox listBox1;
        with this line:
           private XLISTBOXCS.XListBoxCS listBox1;

Now you can test the listbox by adding some lines to your form:

namespace MyApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            listBox1.Add("Hello World");
            listBox1.Add(Color.FromName("Lime"), Color.FromName("Black"), "Hello World");
        }
    }
}

And this is what you should see:

screenshot

Revision History

Version 1.1

  • Initial public release

Buy latest version

Buy XListBoxCS 1.1 license – $30.00 per developer