题目要求:
编写一个Window应用程序,利用Graphics对象的DrawString方法在窗体上绘制文字“山东省烟台大学”,要求用一幅图片填充。
输入代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Ziti
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Image image = Image.FromFile(Application.StartupPath + @"\12.jpg");
TextureBrush brush = new TextureBrush(image);
Font f = new Font("黑体", 60, FontStyle.Underline ^ FontStyle.Bold);
g.DrawString("山东省烟台大学", f, brush, new Point(10, 10));
g.Dispose();
}
}
}
运行截图:
总结:
TextureBrush的用法