zoukankan      html  css  js  c++  java
  • c# 给button添加不规则的图片以及用pictureBox替代button响应点击事件

    1.Flat button

    用这个方法,前提是要把button的type设置为Flat

    button1.TabStop = false;
    button1.FlatAppearance.BorderSize = 0; button1.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); //设置边框的颜色Transparent button1.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 255, 255, 255); //设置鼠标经过时候的背景颜色Transparent button1.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 255, 255, 255); //设置鼠标按下时候的背景颜色Transparent

    这样按钮的效果图如下

    后面的颜色是窗体的颜色不是按钮的颜色。

    接下来响应点击事件。

    //鼠标落下设置一张图片
    private void button1_MouseDown(object sender, MouseEventArgs e)
    {
         this.button1.Image = Image.FromFile(@"../../images/close_click.png");
    }
    
    //鼠标弹起恢复原来图片
    private void button1_MouseUp(object sender, MouseEventArgs e)
    {
         this.button1.Image = Image.FromFile(@"../../images/close_default.png");
    }
    
    //响应点击事件
    private void button1_Click(object sender, EventArgs e)
    {
         MessageBox.Show("I'm normal button");
    }

    2.用pictureBox

     private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
     {
          this.pictureBox2.Image = Image.FromFile(@"../../images/close_click.png");
    }
    
    private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
    {
         this.pictureBox2.Image = Image.FromFile(@"../../images/close_default.png");
    }
    
    private void pictureBox2_Click(object sender, EventArgs e)
    {
          MessageBox.Show("I'm closed");
    }
  • 相关阅读:
    mui 单页面下拉刷新
    phpStorm格式化代码快捷键
    mui 子页面切换父页面底部导航
    Java连接Mysql的基本用法
    string替换所有指定字符串(C++)
    MySql与Java的时间类型
    MYSQL中防止插入重复记录的解决方案(无重复值更新)
    Java数据库连接池封装与用法
    Java中数据库连接池原理机制的详细讲解(转)
    Fedora14使用yum安装mysql
  • 原文地址:https://www.cnblogs.com/lihaibo-Leao/p/3303003.html
Copyright © 2011-2022 走看看