public partial class TextureBruse : Form


...{

private Image theimage;

private Image smallimage;


public TextureBruse()


...{

InitializeComponent();


SetStyle(ControlStyles.Opaque, true);

Bounds = new Rectangle(0, 0, 500, 500);

theimage = new Bitmap("ico.gif"); //Application.StartupPath+@"ico.gif"

smallimage = new Bitmap(theimage, new Size(theimage.Width, theimage.Height));

}

protected override void OnPaint(PaintEventArgs e)


...{

Graphics g = e.Graphics;

g.FillRectangle(Brushes.White,ClIEntRectangle);

Brush brush = new TextureBrush(smallimage, new&nbs(0, 0,smallimage.Width, smallimage.Height));

//用圖像創建畫筆,來繪制圖像

g.FillEllipse(brush, new Rectangle(0,200,200,200));

//用圖像創建剛筆,來繪制圖像

Pen pen=new Pen(brush,20);

g.DrawRectangle(pen, new Rectangle(250, 200, 200, 200));

//用圖像繪製文本

Font font = new Font("Times New Roman", 40, FontStyle.Bold | FontStyle.Italic);

g.DrawString("Hello Image !!", font, brush, new Rectangle(0,0,500,font.Height));


brush.Dispose();

font.Dispose();

}

}
運行效果圖:
