ARCed.XnaExtensions.DrawString C# (CSharp) Method

DrawString() public static method

Draws the specified string using the given font and location.
Without the use of a ContentPipeline, it is necessary to use GDI+ to draw the font onto a bitmap and transfer it to a texture.
public static DrawString ( this batch, string text, Font font, Microsoft.Xna.Framework.Color color, Rectangle rect ) : void
batch this SpriteBatch to draw the string
text string Text to draw
font System.Drawing.Font Font to draw text with.
color Microsoft.Xna.Framework.Color Color of the text.
rect Microsoft.Xna.Framework.Rectangle Rectangle where text will be drawn.
return void
        public static void DrawString(this SpriteBatch batch, string text,
            Font font, Color color, Rectangle rect)
        {
            using (var bmp = new Bitmap(rect.Width, rect.Height))
            {
                using (var g = Graphics.FromImage(bmp))
                {
                    g.DrawString(text, font, Brushes.White,
                        new PointF(0, 0));
                    batch.Draw(bmp.ToTexture(batch.GraphicsDevice), rect, color);
                }
            }
        }