我需要你的帮助!!!! [英] I need yours help please!!!!

查看:74
本文介绍了我需要你的帮助!!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有人来帮助我如何创建一个按钮,当你将光标移动到这个随机移动窗口时,永远不能点击....

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 ....

推荐答案

捕获表格的鼠标移动。

一旦x和y坐标映射到按钮的位置/是共同的,请更改左侧和顶部按钮的属性。



这应该 [ ^ ]帮助和给予你知道如何继续。
Capture the mousemove for the form.
As soon as the x and y co-ordinates map to the button''s location / are co-oridnates, change the left and top properties of the button.

This should[^] help and give you an idea on how to proceed.


试试这个:

Try this:
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);
}


这篇关于我需要你的帮助!!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆