Monthly Archives: July 2013

Compare floating-point values safely in C#

The computer stores values in binary using 0s and 1s. That means it cannot store all possible decimal values exactly. Sometimes when you multiply or divide two floating-point values, the computer may be unable to store the result exactly. Usually … Continue reading

Posted in calculations, mathematics | 2 Comments

Resize a RichTextBox to fit its contents in C#

The example Resize a TextBox to fit its text in C# shows how to make a TextBox fit its text. That example uses a TextRenderer to determine how big the control’s text will be when it is drawn on the … Continue reading

Posted in controls | 5 Comments

Blank the WebBrowser control in C#

If a program displays a web page in a WebBrowser control and then that page become irrelevant to the program, you may want to blank the control. Doing that is as easy as making the control navigate to the special … Continue reading

Posted in controls, internet, web | Leave a comment

Make a scrolled window in C#

Over the years, I’ve posted literally thousands of tips, tricks, and examples on my VB Helper web site. I’ve posted many examples over such a long time that I don’t remember what I’ve also posted to this site. This is … Continue reading

Posted in miscellany | Leave a comment

Resize a TextBox to fit its text in C#

As you type, this example resizes its TextBox to fit its contents. The key is the following AutoSizeTextBox method. // Make the TextBox fit its contents. private void AutoSizeTextBox(TextBox txt) { const int x_margin = 0; const int y_margin = … Continue reading

Posted in controls | Leave a comment

Align lines of text in C#

The example Draw a paragraph one line at a time in C# shows how to draw the lines of a paragraph one at a time. Once you can do that, it’s a simple matter to align the lines on the … Continue reading

Posted in graphics, printing, strings | Leave a comment

Align lines of text in C#

The example Draw a paragraph one line at a time in C# shows how to draw the lines of a paragraph one at a time. Once you can do that, it’s a simple matter to align the lines on the … Continue reading

Posted in graphics, printing, strings | Leave a comment

Draw a paragraph one line at a time in C#

My next few posts show how to draw text on a Graphics object in various ways. The examples draw on PictureBoxes but it’s important to remember that they work with any Graphics object including the one that you are given … Continue reading

Posted in graphics, printing, strings | Leave a comment

Print values in a grid in C#

This example prints a set of values in a grid. The following DrawValueGrid method does all of the printing. It’s long but the pieces are relatively simple. // Draw a grid containing the indicated values. private void DrawValueGrid(Graphics gr, RectangleF … Continue reading

Posted in graphics, printing | Leave a comment