Monthly Archives: January 2013

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

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

Posted in controls | Leave a comment

Generate letters (or other random values) with given frequencies in C#

This example generates random letters with the frequencies they show in normal English text. The following code shows how the example gets started. // The letter frequencies. See: // en.wikipedia.org/wiki/Letter_frequency private float[] Frequencies = { 8.167f, 1.492f, 2.782f, 4.253f, 12.702f, … Continue reading

Posted in mathematics | Leave a comment

Embed a text file in a project as a resource in C#

This is handy for including a large amount of text in a project without adding it within the code and without including a file in the program’s installation package. Open the Project menu and select Properties. Open the Add Resource … Continue reading

Posted in files | Leave a comment

Make a class define and raise events in C#

This example uses a BannkAccount class to manage a bank account. If the program tries to remove more money from the account than its current balance, the BankAccount object raises an Overdrawn event. The event includes two parameters: an object … Continue reading

Posted in classes, events | 3 Comments

Use statement lambdas in C#

The example Use lambda expressions in C# showed how to use lambda expressions to concisely create an anonymous method that takes parameters and returns a value. The following code shows one of the lambda expressions that example used. private void … Continue reading

Posted in algorithms, graphics, variables | Leave a comment

Use lambda expressions in C#

A lambda expression is basically just a shorthand notation for making an anonymous method. There are a couple of formats, the simplest of which has the following syntax. x => expression Here expression is an expression involving the variable x. … Continue reading

Posted in algorithms, graphics, variables | Leave a comment

Use anonymous methods in C#

The previous post Use the predefined Action, Func, and EventHandler delegate types in C# explains how to use the predefined generic Func, Action, and EventHandler delegate types to graph four functions F(x, y). It uses the following code to define … Continue reading

Posted in algorithms, graphics, variables | Leave a comment

Use the predefined Action, Func, and EventHandler delegate types in C#

This and the next couple of posts discuss delegates and the somewhat related topics of anonymous methods and lambda expressions. Other examples such as Use delegates to pass a method’s address to another method in C# show how to use … Continue reading

Posted in algorithms, graphics, variables | Leave a comment