zoukankan      html  css  js  c++  java
  • 30.winform之按钮的MouseEnter

    效果

    实现


    代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Do_you_love_me {
        public partial class Form1 : Form {
            public Form1() {
                InitializeComponent();
            }
    
            /// <summary>
            /// 当鼠标进入按钮的可见部分时,给按钮一个新的坐标
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button2_MouseEnter(object sender, EventArgs e) {
                //给按钮一个新的坐标
                //这个按钮活动的最大宽度就是 窗体的宽度减去按钮的宽度
                //ClientSize获取或设置窗体工作区的大小
                int x = this.ClientSize.Width - btnUnLove.Width;
                int y = this.ClientSize.Height - btnUnLove.Height;
    
                Random r = new Random();
                //要给按钮一个随机坐标
                btnUnLove.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1));
            }
    
            private void button1_Click(object sender, EventArgs e) {
                MessageBox.Show("爱你");
                this.Close();//关闭主窗体
            }
    
    
        }
    }
    
    
  • 相关阅读:
    1052. 卖个萌 (20)
    1051. 复数乘法 (15)
    1050. 螺旋矩阵(25)
    1049. 数列的片段和(20)
    1048. 数字加密(20)
    1047. 编程团体赛(20)
    1046. 划拳(15)
    怎么用js代码改变单选框的选中状态
    Dom操作--全选反选
    Scoket简介
  • 原文地址:https://www.cnblogs.com/lz32158/p/12968285.html
Copyright © 2011-2022 走看看