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;
        }
    }
  • 相关阅读:
    【转】Reactor与Proactor两种模式区别
    [转] 比较清楚的阻塞与非阻塞和同步与异步
    一眨眼已做开发十年
    【转】Linux CentOS内核编译:下载CentOS源码、编译2.6.32-220的错误(apic.c:819 error 'numi_watchdog' undeclared)
    [转] Makefile经典教程(掌握这些足够)
    [转]centos 下 autoconf版本升级
    centos安装CODEBLOCKS
    【转】linux 编译安装nginx,配置自启动脚本
    Install Qt creator
    LeetCode 983. Minimum Cost For Tickets
  • 原文地址:https://www.cnblogs.com/Hsppl/p/2601017.html
Copyright © 2011-2022 走看看