• [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;
        }
    }
  • 相关阅读:
    利用UltraScale和UltraScale+FPGA和MPSOC加速DSP设计生产力
    ARM系列处理器和架构
    Thumb扩展
    使用Redis分布式锁处理并发,解决超卖问题
    idea指定启动参数、环境变量
    Json返回结果为null属性不显示解决
    Spring Cloud Zuul 网关服务的fallback
    记录一次URL中有特殊字符怎么处理?
    logback的使用和logback.xml详解
    通过gitlab的webhook触发Jenkins自动构建设置
  • 原文地址:https://www.cnblogs.com/Hsppl/p/2601017.html
Copyright © 2020-2023  润新知