Tag Archives: user interface

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

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

Position a form over another form in C#

When you click this example’s button, the program uses the following code to display a new instance of the main form positioned next to the button’s lower left corner (as shown in the picture). // Position a new instance of … Continue reading

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

Make a context-sensitive AcceptButton in C#

You’ve probably seen applications, often on web sites, where the action that a form takes when you press Enter depends on the control that has focus at the time. For example, many login pages have a place for you to … Continue reading

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

Initialize a TreeView control to display a directory hierarchy in C#

This example adds the following LoadFromDirectory extension method to the TreeView control. // Initialize the TreeView from a directory, // its subdirectories, and their files. public static void LoadFromDirectory(this TreeView trv, string directory, int folder_img, int file_img) { DirectoryInfo dir_info … Continue reading

Posted in controls, directories, extension methods, files, user interface | Tagged , , , , , , , , , , , , , | Leave a comment

Use a timer to make a form TopMost or BottomMost in C#

The example Make a form TopMost or BottomMost in C# uses one method for making a form bottommost. It overrides the form’s WndProc method and looks for the message WM_WINDOWPOSCHANGING. When it finds that message, the program uses the SetWindowPos … Continue reading

Posted in API, controls, forms, user interface | Tagged , , , , , , , , , , , , , , , , , | 2 Comments

Make a form TopMost or BottomMost in C#

Keeping a form on top of other windows is simple. Just set the form’s TopMost property to true. Keeping a form below other windows is harder. To do that, the program must override its WndProc method, look for messages that … Continue reading

Posted in API, controls, forms | Tagged , , , , , , , , , , , , , , , , , | 1 Comment

Make a StatusLabel display its text even if it doesn’t fit in C#

If the text displayed in a StatusLabel is too long to fit in the containing StatusStrip control, then by default the StatusLabel doesn’t display anything. I don’t know what the rationale behind that it is, but it makes the StatusLabel … Continue reading

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

A quick note on error messages

I went to a local museum the other day and when the attendant scanned by membership card his computer said: Object not set to a reference of an object. Because we’re programmers, you and I know what that means (more … Continue reading

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

Use a symbiote to graphically select hours in C#

This example modifies the previous example Graphically select hours in C# so it uses a symbiote class. That example shows how to use a PictureBox to let the user select a range of hours. If you want to let the … Continue reading

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