Monthly Archives: December 2017

Download and display a text file whenever a program starts in C#

When this example starts, it downloads a file from the internet and displays it. You could do something similar to display a message of the day or announcements for your program. The program uses the following Load event handler to … Continue reading

Posted in files, internet, web | Tagged , , , , , , , , , | Leave a comment

Anatomy of an example

Usually I have to think of example ideas myself, but sometimes someone asks me a question that leads to an interesting post. Occasionally the original question leads to a new idea, which leads to another idea, and so on. This … Continue reading

Posted in miscellany | Tagged , , , , , | 2 Comments

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

Draw aligned columns of data in C#

This example draws a series of rows with aligned columns either left or right justified. The program uses the following code to define the data it will draw and the row and column alignments. // The values. private string[][] Values … Continue reading

Posted in fonts, graphics, lists | Tagged , , , , , , , , , , , , , , , | 1 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

Delete files quickly and easily in C#

A while ago, I needed to delete files that were created when I opened old projects in a newer version of Visual Studio. LOTS of files. (As far as I know, there’s no way to tell Visual Studio not to … Continue reading

Posted in files, system | 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

Find a form’s screen in C#

Find a form’s screen can be an issue if the user is using more than one monitor. When this program starts, it uses the following code to get the Screen object that holds the form and display its device name, … Continue reading

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

Position a form so it does not stick off the edge of the screen in C#

In the picture, the main program (on the bottom) initially positioned the top form so it was hanging off the right and bottom edges of the screen. The program’s code moved the form so it fit in the screen’s lower … Continue reading

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