Category Archives: user interface

Make a skinned form in C#, Part 1 (the controls)

A skinned form is just plain cool. It adds a bit of interest to the square windows used by every other application. By setting a Windows Form’s TransparencyKey property to a color that should not be rendered, you can make … Continue reading

Posted in user interface | Tagged , , , , , , , | 1 Comment

Make a PictureBox act like a button in C#

This program uses several images to make a PictureBox behave like a button. These images give you complete control over how the “button” looks as it is pressed and released. A button should have these behaviors: When the mouse is … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , | Leave a comment

Display a horizontal scrollbar in a ListBox in C#

Displaying a horizontal scrollbar is easy but useful. If you need to display some long values in a ListBox, you may want to be able to scroll to the right to see the ends of the values. For example, this … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , | Leave a comment

Resize a RichTextBox to fit its contents in C#

This example shows how you can resize a RichTextBox control so it fits the text and images that it contains. The example Resize a TextBox to fit its text in C# shows how to make a TextBox fit its text. … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , | 5 Comments

Make a scrolled window in C#

Making a scrolled window is really easy, at least if you’ve seen how to do it before. If you haven’t seen it, you can spend a lot of time building your own scrolled window out of PictureBox, VerticalScrollBar, and HorizontalScrollBar … Continue reading

Posted in miscellany, user interface | Tagged , , , , , , , , , | Leave a comment

Resize a TextBox to fit its text in C#

This example shows how you can resize a TextBox to fit its contents as the user types. The key is the following AutoSizeTextBox method. // Make the TextBox fit its contents. private void AutoSizeTextBox(TextBox txt) { const int x_margin = … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , | 1 Comment

Make an owner-drawn ListBox that justifies columns in C#

This example shows how you can use an owner-drawn ListBox to left and right align values in columns. The following examples show different ways to align values in columns. Draw aligned columns of data in C# Format values in a … Continue reading

Posted in controls, fonts, graphics, lists, user interface | Tagged , , , , , , , , , , , , , , , , , , | Leave a comment

Format values in a ListBox in C#

The ListBox control’s FormatString property determines how the control formats the values it displays. This can be particularly useful if you need to display values that need special formatting such as dates and currency amounts. When it starts, this example … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , | Leave a comment

Right-justify values in a ListBox in C#

Sometimes you may like to right-justify values in a ListBox. For example, you might want to align numbers so they line up at their decimal points. This example uses the following code to right-justify lists of numbers. private void Form1_Load(object … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , | Leave a comment

Understand the startup form (or main form) in C#

When a C# Windows Forms program starts, it displays a startup form. That form has a special place in the program’s life cycle. If that form ever closes, the application ends. The program can create and close as many other … Continue reading

Posted in forms, user interface | Tagged , , , , , , , , | Leave a comment