zoukankan      html  css  js  c++  java
  • [C#][Winfrom]自定义窗体主题

    首先在窗体类里面声明两个变量,来监视鼠标的动作

    //鼠标按下标识
     bool mouseDown = false;
    Point mouseOffset;

    在Load事件里加载所有的图片

    if (File.Exists(GlobalInfo.AppPath + "\\Picture\\login.png"))
        this.BackgroundImage = new Bitmap(GlobalInfo.AppPath + "\\Picture\\login.png");
     
    if (File.Exists(GlobalInfo.AppPath + "\\Picture\\button.png"))
    {
        this.simpleButton1.ImageLocation = ImageLocation.MiddleCenter;
        this.simpleButton1.Image = new Bitmap(GlobalInfo.AppPath + "\\Picture\\button.png");
     
        this.simpleButton2.ImageLocation = ImageLocation.MiddleCenter;
        this.simpleButton2.Image = new Bitmap(GlobalInfo.AppPath + \\Picture\\button.png);
    }

    绘制按钮的时候添加上文字

    //绘制登录按钮
    private void simpleButton1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawString("登录", new Font("新宋体", 12, FontStyle.Bold), Brushes.White, 30, 8);
    }

    窗体的鼠标事件

    //鼠标按下
    private void FrmLogin_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            mouseDown = true;
            mouseOffset = new Point(-e.X, -e.Y);
        }
    }
    //鼠标松开
    private void FrmLogin_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            mouseDown = false;
        }
    }
    //鼠标按下移动
    private void FrmLogin_MouseMove(object sender, MouseEventArgs e)
    {
        if (mouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X, mouseOffset.Y);
            this.Location = mousePos;
        }
    }
  • 相关阅读:
    建设Kubernetes生产环境的16条建议
    深度长文:深入理解Ceph存储架构
    10个最危险的Linux命令,希望你牢记在心
    完美排查入侵者的 10 个方法和 1 个解决思路
    基于Docker&Kubernetes构建PaaS平台基础知识梳理
    Linux入门进阶
    (七)服务接口调用-OpenFeign
    (六)服务调用负载均衡-Ribbon
    (五)Eureka替换方案-Consul
    (四)Eureka替换方案-Zookeeper
  • 原文地址:https://www.cnblogs.com/Hsppl/p/2601017.html
Copyright © 2011-2022 走看看