Use TexturedBrush to draw string : Text Rendering « 2D Graphics « C# / C Sharp






Use TexturedBrush to draw string

Use TexturedBrush to draw string
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class MainForm : Form {

    private Brush texturedTextBrush;
    private Brush texturedBGroundBrush;

    public MainForm() {
        Image bGroundBrushImage = new Bitmap("Clouds.bmp");
        texturedBGroundBrush = new TextureBrush(bGroundBrushImage);
        Image textBrushImage = new Bitmap("Soap Bubbles.bmp");
        texturedTextBrush = new TextureBrush(textBrushImage);
    }

    protected void OnPaint(PaintEventArgs e) {
        Graphics g = e.Graphics;
        Rectangle r = ClientRectangle;
        g.FillRectangle(texturedBGroundBrush, r);
        g.DrawString("Bitmaps as brushes",
                     new Font("Arial", 30,
                     FontStyle.Bold | FontStyle.Italic),
                     texturedTextBrush,
                     r);

    }
    public static void Main(){
       Application.Run(new MainForm());
    }
}

 








Related examples in the same category

1.Hotkey Prefix
2.Text Rendering Hint: SingleBitPerPixelGridFitText Rendering Hint: SingleBitPerPixelGridFit
3.Text Rendering Hint: AntiAliasGridFitText Rendering Hint: AntiAliasGridFit
4.Text Rendering Hint: ClearTypeGridFitText Rendering Hint: ClearTypeGridFit
5.TextRenderingHint: Anti-Aliased Text
6.DrawString with solid brush, string format
7.DrawString with solid brush and rectangle
8.Draw string with hatch brush