• WinForm生成不规则窗体


    有的时候你需要让你的窗体更酷点,不想要规规矩矩的用那个方方正正的窗体,那么接下来的代码可能是你想要的。

    首先你可以准备一张你想要的窗体的形状的图片。如下所示

    我所需要的窗体只包含除了白色的部分像素点,当然你可以准备一张黑白图片,如下所示

    我们写一个函数来获取我们窗体需要的区域(这个当然需要你的窗体比你的这张图要大),如下:

    public GraphicsPath SetAlltypeWindow(Control form,string regionBMP, Color transparentColor)

            {

                GraphicsPath path =new GraphicsPath();

                if (File.Exists(regionBMP))

                {

                    Bitmap bitmap =new Bitmap(regionBMP);

                    form.BackgroundImage = bitmap;

                    form.Width = bitmap.Width;

                    form.Height = bitmap.Height;

                    for (int x = 0; x < bitmap.Width; x++)

                    {

                        for (int y = 0; y < bitmap.Height; y++)

                        {

                            Color c = bitmap.GetPixel(x, y);

                            if (c != transparentColor)

                            {

                                path.AddRectangle(newRectangle(x, y, 1, 1));

                            }

                        }

                    }

                }

                return path;

            }

    然后在窗体中指定窗体的区域(注意,窗体的FormBorderStyle=None,否则会有偏移)

      private void Form1_Load(object sender, EventArgs e)

            {

                this.Region = new Region(SetAlltypeWindow(this,"形状图片的路径",Color.FromArgb(255,255,255,255)));

    }

    这样既可得到图片所示形状的窗体。试试看空白的地方是可以穿透的。说明这个是镂空了的窗体。

     

     
     
  • 相关阅读:
    【WebGoat笔记】 CrossSite Scripting(XSS)
    SQL注入测试工具:Pangolin(穿山甲)
    SQL注入测试工具:Pangolin(穿山甲)
    js取两日期差,包含周六周日?
    CrossSite Scripting(XSS): 跨站脚本攻击介绍
    apmserv虚拟主机不能用set_time_limit(0);
    名称 不是有效的标识符 sql
    最佳的75个安全测试工具
    fzu 1686(DLX 重复点覆盖)
    hdu 3529(DLX)
  • 原文地址:https://www.cnblogs.com/wanzhongjun/p/6388514.html
Copyright © 2020-2023  润新知