GDI 绘图

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);
        }

 

效果图如下:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值