具体代码如下 by 程序杰杰
#region 控件变大效果 nxj private async void MouseIn(int pxNum, int count) { bool fuwei = false; for (int i = 0; i < count; i++) { if (this.button1.Width > widthYS + count * pxNum) { fuwei = true; } if (button1.Height > heightYS + count * pxNum) { fuwei = true; } if (button1.Location.X < PointxYS - (count * pxNum) / 2) { fuwei = true; }//因为x与y同步变化,因此只判断任何一个就可以 if (fuwei) { this.button1.Width = widthYS + count * pxNum; button1.Height = heightYS + count * pxNum; button1.Location = new Point(PointxYS - (count * pxNum) / 2, PointyYS - (count * pxNum) / 2); return; } await Task.Delay(30); this.button1.Width += 2 * pxNum; this.button1.Height += 2 * pxNum; this.button1.Location = new Point(this.button1.Location.X - pxNum, this.button1.Location.Y - pxNum); } } #endregion #region 控件变小,还原 nxj private async void MouseOut(int pxNum, int count) { bool fuwei = false; for (int i = 0; i < count; i++) { //在加个变量,判断是否已经进入任何一个,如果进入任何一个就全部设置,不要这样判断一个就写一个,然后跳出循环,结束 if (this.button1.Width < widthYS) { fuwei = true; } if (button1.Height < heightYS) { fuwei = true; } if (button1.Location.X > PointxYS) { fuwei = true; }//因为x与y同步变化,因此只判断任何一个就可以 if (fuwei) { this.button1.Width = widthYS; button1.Height = heightYS; button1.Location = new Point(PointxYS, PointyYS); return; } await Task.Delay(30); this.button1.Width -= 2* pxNum; this.button1.Height -= 2* pxNum; this.button1.Location = new Point(this.button1.Location.X + pxNum, this.button1.Location.Y + pxNum); } } #endregion
使用代码如下