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 WindowsFormsApp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { label1.Text = "很好,天天向上"; } private void button2_Click(object sender, EventArgs e) { label1.Text = "想多了,还没睡醒吧!!!"; } private void button2_MouseEnter(object sender, EventArgs e) { Random r = new Random (); button2.Left = r.Next(this.ClientRectangle.Left, this.ClientRectangle.Width - button2.width); button2.Top = r.Next(this.clientRectangle.Top, this.ClientRectangle.Height - button2.Height);
时间: 2024-02-14 15:23:20 浏览: 102
libemgucv-windesktop-3.4.1.2976.exe
我发现你在button2_MouseEnter方法中使用了小写的width和clientRectangle,这可能导致编译错误。正确的写法应该是大写字母的Width和ClientRectangle。此外,你还可以考虑添加一些边界检查,以确保button2不会超出窗口范围。例如,你可以使用Math.Max和Math.Min方法来限制button2的位置不超出窗口的左右和上下边界。
阅读全文