首页 > Windows开发 > 详细

创建非矩形窗体

时间:2018-12-13 00:50:37      阅读:161      评论:0      收藏:0      [点我收藏+]

实现效果:

  技术分享图片

 知识运用:

  通过重写窗体的OnPaint方法 在其中对窗体进行重绘 并使用透明色将窗体设置为透明来实现

  OnPaint方法: 用来从新绘制窗体图像 

  protected override void OnPaint(PaintEventArgs e) //painteventargs为Paint事件提供数据

  Bitmap类的MakeTransparent方法: 使用指定颜色对位图进行透明  

     public void MakeTransparent(Color transparentColor)  //transparentColor:Color结构 表是使之透明的颜色

  this.BackColor = System.Drawing.SystemColors.Control;

  this.TransparencyKey = System.Drawing.SystemColors.Control;

实现代码:  

        private void Form1_Load(object sender, EventArgs e)
        {
            bit = new Bitmap(Properties.Resources.bit);//从指定的图像初始化Bitmap对象
            bit.MakeTransparent(Color.Black);       //使用指定的颜色对Bitmap位图透明
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawImage(bit, new Point(0, 0));   //在窗体上绘制图片
        }

 

创建非矩形窗体

原文:https://www.cnblogs.com/feiyucha/p/10111666.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!