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();//关闭主窗体
            }
    
    
        }
    }
    
    
  • 相关阅读:
    12.18-java复习-UserBean
    12.17-javaweb复习
    12.16-javaweb复习
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
    java建议
    个人表现
    今日总结
    今日总结
    今日总结
    今日总结
  • 原文地址:https://www.cnblogs.com/lz32158/p/12968285.html
Copyright © 2011-2022 走看看