本文介绍了我需要你的帮助!!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要有人来帮助我如何创建一个按钮,当你将光标移动到这个随机移动窗口时,永远不能点击....
I need someone to help me on how to create a button that when you move the cursor over this random move the window, and never able to click on the ....
推荐答案
private void button1_MouseHover(object sender, EventArgs e)
{
SetNewPosition();
}
private void button1_MouseEnter(object sender, EventArgs e)
{
SetNewPosition();
}
private void SetNewPosition()
{
this.SuspendLayout();
GetNewPosition(button1);
this.ResumeLayout();
}
private void GetNewPosition(Button button)
{
int screenHeight = this.Bounds.Height;
int screenWidth = this.Bounds.Width;
Random rnd = new Random(100);
int rand = rnd.Next(screenHeight/10);
Point parentPoint = button.Location;
int childHeight = button.Height;
int childWidth = button.Width;
int resultX;
int resultY;
resultY = parentPoint.Y + childHeight + rand;
resultX = parentPoint.X + childWidth + rand;
if (screenHeight < resultY + childHeight)
resultY = childHeight;
if (screenWidth < resultX + childWidth)
resultX = childWidth;
button.Location = new Point(resultX, resultY);
}
这篇关于我需要你的帮助!!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!