简体   繁体   English

如何禁用鼠标单击突出显示?

[英]How can I disable mouse click highlight?

I have a scientific calculator application in C#. 我在C#中有一个科学的计算器应用程序。 I'd like to disable click highlight, you know, I click the button with mouse, and the button will be highlighted. 我想禁用点击突出显示,您知道,我用鼠标单击了按钮,按钮将被突出显示。 It's very annoying, because I can't use the enter key event, when the button is highlighted, and in this case not working the execute function with enter. 这很烦人,因为突出显示按钮时我无法使用enter键事件,在这种情况下,我无法使用enter执行函数。 The calculator use the highlighted button instead of the execute function. 计算器使用突出显示的按钮代替执行功能。

I hope my problem is understandable. 我希望我的问题是可以理解的。 What can I do? 我能做什么?

In your form, try setting KeyPreview = true and override OnKeyDown : 在您的表单中,尝试设置KeyPreview = true并覆盖OnKeyDown

public ExampleForm()
{
    InitializeComponent();

    KeyPreview = true;
}

protected override void OnKeyDown(KeyEventArgs e)
{
    base.OnKeyDown(e);

    if (e.KeyData == Keys.Enter)
    {
        e.Handled = true;

        // Execute calculator function
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM