Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Convert Text to Image

, 27 Nov 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
I'd like to offer a "funny" alternative by using a dummy TextBox. public static Bitmap GetPlainTextBitmap(string strText, Font font, Color colorBack, Color colorText, Size sizeTargetBitmap) { // Create a dummy TextBox TextBox txDummy = new TextBox(); ...
I'd like to offer a "funny" alternative by using a dummy TextBox.
 
public static Bitmap GetPlainTextBitmap(string strText, Font font, Color colorBack, Color colorText, Size sizeTargetBitmap)
        {
            // Create a dummy TextBox 
            TextBox txDummy = new TextBox();
            txDummy.BorderStyle = BorderStyle.None;
            txDummy.Multiline = true;
            // ... and initialize with the given parameters
            txDummy.Size = sizeTargetBitmap;
            txDummy.Text = strText;
            txDummy.Font = font;
            txDummy.BackColor = colorBack;
            txDummy.ForeColor = colorText;
 
            // Now just draw the dummy TextBox to an bitmap
            Bitmap bmp = new Bitmap(txDummy.Width, txDummy.Height);
            txDummy.DrawToBitmap(bmp, txDummy.ClientRectangle);
 
            return bmp;
        }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

johannesnestler

Austria Austria
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 27 Nov 2011
Article Copyright 2011 by johannesnestler
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid