GDI+:Graphics Device Interface Plus也就是图形设备接口,提供了各种丰富的图形图像处理功能;在C#.NET中,使用GDI+处理二维(2D)的图形和图像,使用DirectX处理三维(3D)的图形图像,图形图像处理用到的主要命名空间是System . Drawing:提供了对GDI+基本图形功能的访问,主要有Graphics类、Bitmap类、从Brush类继承的类、Font类、Icon类、Image类、Pen类、Color类等.
自己写个小demo了解基本用法,如下:
private void Init()
{
this.gridControl1.Paint += GridControl1_Paint;
this.simpleButton1.Paint += SimpleButton1_Paint;
this.simpleButton1.Click += SimpleButton1_Click;
DataTable dt = dtInfo();
this.gridControl1.DataSource = dt;
}
/// <summary>
/// 绘制按钮
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
private void SimpleButton1_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
Color c = Color.Red;
Pen p = new Pen(c, 2);
graphics.DrawRectangle(p, new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height));
Font f = new Font("微软雅黑", 18, FontStyle.Regular, GraphicsUnit.Pixel);
c = Color.Green;
string text = "确 定";
graphics.DrawString(text, f, new SolidBrush(c), e.ClipRectangle.X + 22, e.ClipRectangle.Y + 7);
}
/// <summary>
/// GridControl绘制图片和文字
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
private void GridControl1_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
Bitmap bitmap = Resources.当前暂无任务执行;
int x = (gridControl1.Width - bitmap.Width) / 2;
int y = (gridControl1.Height - bitmap.Height) / 2;
graphics.DrawImage(bitmap, x, y);
Font f = new Font("微软雅黑", 18, FontStyle.Regular, GraphicsUnit.Pixel);
Color c = Color.FromArgb(186, 186, 186);
string text = "信息展示";
//graphics.MeasureString(text, f);
x = gridControl1.Left + gridControl1.Width / 2 - 40;
y = y + bitmap.Height + 15;
graphics.DrawString(text, f, new SolidBrush(c), x, y);
}
效果图如下: