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;
        }
    }
  • 相关阅读:
    MyEclipse快捷键大全
    The type 'Microsoft.Office.Interop.Excel.ApplicationClass' has no constructors defined
    ‘Microsoft.Office.Interop.Excel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’
    使用游标循环表的简单DEMO
    URL Records
    一步一步教你实现CTreeCtrl 自绘
    自绘按钮
    UDP文件传输的实现
    美化VC界面(用户登录界面)
    如何截取QQ密码和聊天内容、去掉QQ广告栏、添加QQ尾巴
  • 原文地址:https://www.cnblogs.com/Hsppl/p/2601017.html
Copyright © 2011-2022 走看看