Author Archives: Rod Stephens

Graph a curve in polar coordinates in C#

In Cartesian coordinates, a point is specified by X and Y values. In polar coordinates, a point is specified by r and θ where: r is the point’s radial distance from the origin θ is the angle that gives the … Continue reading

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

Create a PowerPoint presentation from a Word document in C#

This example shows how you can create a PowerPoint presentation containing slides that correspond to selected styles in a Microsoft Word document. How to Use It Enter or select a Word document and a destination PowerPoint presentation. Enter the styles … Continue reading

Posted in interoperability, Office, Word | Tagged , , , , , , , , , , , , , , , | Leave a comment

Compare floating-point values safely in C#

The computer stores values, including floating-point 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 is unable to store the result … Continue reading

Posted in calculations, mathematics | Tagged , , , , , , , , , , , , , | 3 Comments

Resize a RichTextBox to fit its contents in C#

This example shows how you can resize a RichTextBox control so it fits the text and images that it contains. The example Resize a TextBox to fit its text in C# shows how to make a TextBox fit its text. … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , | 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 | Tagged , , , , , , , , , , , | Leave a comment

Make a scrolled window in C#

Making a scrolled window is really easy, at least if you’ve seen how to do it before. If you haven’t seen it, you can spend a lot of time building your own scrolled window out of PictureBox, VerticalScrollBar, and HorizontalScrollBar … Continue reading

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

Resize a TextBox to fit its text in C#

This example shows how you can resize a TextBox to fit its contents as the user types. The key is the following AutoSizeTextBox method. // Make the TextBox fit its contents. private void AutoSizeTextBox(TextBox txt) { const int x_margin = … Continue reading

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

Align text by lines in C#

The example Draw paragraphs 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 text one line at a … Continue reading

Posted in fonts, graphics, printing, strings | Tagged , , , , , , , , , , , , , | 1 Comment

Draw paragraphs one line at a time in C#

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

Posted in graphics, printing, strings | Tagged , , , , , , , , , , | 1 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 | Tagged , , , , , , , , , , | Leave a comment