Simply follow this tutorial if you want to learn how to draw or print text string anywhere on your form.
Drawing String on a Form
The first step to successfully drawing text or strings on your form is to create an easily reusable and accessible void called DrawString. Create this void using the code found below.
public void DrawString(Form Frm, String Str, int Size, Color Clr, float X, float Y)
{
//Setup Graphics, Brushes, Fonts, and Formatting
System.Drawing.Graphics myGraphics = Frm.CreateGraphics();
System.Drawing.Font myFont = new Font("Arial", Size);
System.Drawing.SolidBrush myBrush = new SolidBrush(Clr);
System.Drawing.StringFormat myFormat = new StringFormat();
//Draw the Actual String
myGraphics.DrawString(Str, myFont, myBrush, X, Y, myFormat);
//Dispose of Left Overs
myFont.Dispose();
myBrush.Dispose();
myGraphics.Dispose();
}
Now, in your form's Paint event simply call your newly created DrawString void while supplying your desired parameters, like so:
private void Form1_Paint(object sender, PaintEventArgs e)
{
DrawString(this, "My String", 8, Color.Black, 0, 0);
}
This will draw the string "My String" at the coordinates, left 0, right 0 using the size 8 and the color black. Of course you can replace these parameter with your desired string, size, color, and coordinates.
Conclusion
This is a simple and bare bones way of drawing text strings on your form. However with some tweaking to the DrawString void you can add extra and more advanced functionality, such as font type, brush style, bold, underline, strikeout, and more, to your the DrawString function.
Published by James Cloud
I like to program and do basically anything that has to do with technology and computers. View profile
- Real Estate Specializing: Triple Net Lease PropertyPrimary purpose for a Triple Net Lease (NNN) property, places responsibility to pay all property expenses upon the tenant or Lessor. This type of agreement is along term lease. Best suited for growth industries & econ...
- String, the Ultimate ToolThe different uses of string as a tool in construction.
- Introduction to JavaScript String Regular ExpressionsIn this article I explain the meaning of Regular Expressions and I introduce you to the concept with the JavaScript String object. You start learning what is called Matching.
- Cheap but Beautiful Easter Basket Made from StringWhat's cheaper than string and glue? It doesn't cost much to make this cute string basket!
- Halloween Crafts: Characters You Make from StringWant cheap but impressive Halloween decorations? Get out some glue and string!
- Photoshop Tutorial : How to Apply a Weather Effect to Your Text ?
- Birthday Party Games - Swinging Strings
- A Do-it-yourself Guide to Changing Guitar Strings
- Photoshop Tutorial: How to Change Hair Color in a Photo
- Playing the Strings on the Piano and the Artists / Composers Who've Made it Common
- Photoshop Tutorial: Color Correcting and Tone Enhancing Photographs
- Beginner's Photoshop Tutorial: Learning to Create Your Own Brushes



