Monthly Archives: November 2017

Calculate Fibonacci words in C#

You can find Fibonacci words by concatenating previous Fibonacci words much as you calculate the Fibonacci sequence by adding previous values in the sequence. The first two Fibonacci words are: S0 = 0 S1 = 01 The following Fibonacci words … Continue reading

Posted in algorithms, fractals, graphics, mathematics | Tagged , , , , , , , , , , , | 1 Comment

Use the Stopwatch class to time a program in C#

To measure elapsed time, you can save the current time with DateTime.Now and then compare it to a later time to see how much time has elapsed. The Stopwatch class in the System.Diagnostics namespace makes this a bit easier. It’s … Continue reading

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

Use the BigInteger structure in C#

The long data type can hold values between roughly -9.2 x 1018 and -9.2 x 1018, but sometimes even that range isn’t big enough. The .NET Framework 4.0 (C# 4.0 or Visual Studio 2010) introduced the BigInteger structure to represent … Continue reading

Posted in mathematics | 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

A little light holiday reading

Here are a few book books that make excellent holiday reading! (Actually they make good reading any time. ;-)) The C# Helper Top 100 Interview Puzzles Dissected C# 24-Hour Trainer, 2nd Edition Beginning Software Engineering Essential Algorithms: A Practical Approach … Continue reading

Posted in books | Tagged , , , , , , , , , , , | 2 Comments

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

Cast arrays from one reference type to another in C#

Every C# programmer knows that you can use a cast operator to convert one data type into another. For example, if the Employee class inherits from the Person class, then the following code creates an Employee object and then makes … Continue reading

Posted in arrays, syntax, variables | 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