How to add a Click event to an Ellipse in code behind?

点点圈 提交于 2019-12-10 13:58:51

问题


To add a click event to a Button in C# code behind, I can do this

Button btn = new Button;
btn.Click += btn_Click;

What if I have an Ellipse, which does not contain a Click?

Ellipse e = new Ellipse;
e.??? += e_Click;

回答1:


Maybe the MouseUp event will serve your purpose. Try

Ellipse ellipse = new Ellipse();
ellipse.MouseUp += ellipse_MouseUp;

private void ellipse_MouseUp(object sender, MouseButtonEventArgs e)
{
   ...
}



回答2:


One way to do that is make button an ellipse and attatch .Click Event handler.

<Button>
    <Button.Template>
        <ControlTemplate>
            <Ellipse .../>
        </ControlTemplate>
    </Button.Template>
</Button>


来源:https://stackoverflow.com/questions/5560952/how-to-add-a-click-event-to-an-ellipse-in-code-behind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!