C#我有一个带背景图片的按钮。如何在一定条件下触发mouseleave事件? [英] C# I have a button with background image. How to trigger a mouseleave event with a certain condition?

查看:110
本文介绍了C#我有一个带背景图片的按钮。如何在一定条件下触发mouseleave事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带背景的按钮。我创建了mouseenter& mouseleave事件。在mouseleave事件中,如果鼠标光标在2个坐标之外,它将触发mouseleave事件。



我的问题是当我离开500X250矩形时,它会触发mouseleave。我希望它能在250X125矩形中触发。



我尝试过:



I have a button with a background. I created mouseenter & mouseleave event. In the mouseleave event, if a mouse cursor is outside of 2 coordinates it will trigger the mouseleave event.

my problem is when i leave in 500X250 rectangle, it will trigger the mouseleave. i want it to trigger in 250X125 rectangle.

What I have tried:

private void Button_SpanMouseEnter(object sender, EventArgs e)
    {
        Button x = sender as Button;
        x.Size = new Size(500, 250);
        x.Location = new Point(0, 0);
    }

    private void Button_SpanMouseLeave(object sender, EventArgs e)
    {
        Button x = sender as Button;

        //If cursor is outside of this coordinates(0,0) & (250,125)
        //it will trigger this size
        x.Size = new Size(250,125);
        x.Location = new Point(0, 0);
    }

推荐答案

是的。你可以有带背景图片的按钮。



检查按钮的 BackgroundImage 属性。



我认为以下解决方案适合您的情况。



只需放置面板 尺寸 250X125 )你想要按钮。设置该面板的backgroundImage属性。



现在,因为面板在按钮上。您可以使用面板的 Mouseleave 事件来满足您的要求。



此外,正如您在在两个矩形的情况下,你可以使用两个面板。大面积的外面板(500X250矩形),作为内面板(250X125矩形。)。



现在编写内部面板的鼠标离开事件。确保两个面板具有相同的背景,内部面板没有边框,因此它显示为用户的单个面板。
yes. you can have button with background image .

Check for BackgroundImage property of a button.

I think the below solution suits your scenario.

Just put a panel of the size( 250X125 ) you want on the button. Set the backgroundImage property for that panel.

Now since the panel is on the button . You can use Mouseleave event of the panel to fulfill your requirement.

Also, as you mentioned in the question in case of two rectangles, you can use two panels.the outer panel of large size (500X250 rectangle), where as the inner panel (250X125 rectangle.).

Now write the event for Mouse leave of the inner panel. Make sure both panels have same background and inner panel has no borders, so that it appears a single panel for the user.


这篇关于C#我有一个带背景图片的按钮。如何在一定条件下触发mouseleave事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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