在鼠标悬停在标签上的同时按F1键时,打开.chm帮助文件 [英] Open a .chm help file when F1 is pressed while mouse is over label

查看:103
本文介绍了在鼠标悬停在标签上的同时按F1键时,打开.chm帮助文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

您能帮我在Windows窗体上实现帮助功能吗?

我试图在需要显示一些数据的Windows窗体上实现帮助功能.我在将标签与帮助文件相关联时遇到问题.标签位于用户控件上.当鼠标悬停在标签上方时,按F1键时,我需要能够打开帮助文件.

该帮助在功能上适用于文本框,但在显示某些数据的标签上却无法使用.

Lora

Hello All,

Could you please help me to implement help functionality on my windows form?

I am trying to implement help functionality on my Windows forms where I need to display some data. I have an issue to associate the label with help file. The label is located on user control. I need to be able to open help file when I press F1 key while my mouse is over label.

The help functionally is working for text boxes but I can not get it for labels where some data are displayed.

Lora

推荐答案

这可能是因为标签不是焦点突出的控件.您可以在其MouseHover事件处理程序中将焦点设置为标签.然后,您将不得不将标签控件与您的HelpProvider控件相关联.完成此操作后,它应该可以正常工作.遵循以下代码段将有所帮助.

标签的事件处理程序:

That may be because the label is not the focussed control. You can set the focus to the label in it''s MouseHover event handler. Then, you will have to associate the label control with your HelpProvider control. Once you have done this, it should work fine. Following code snippets should help.

Event handlers for the label:

private void LabelMouseHover(object sender, MouseEventArgs e){
(sender as Label).Focus();
}

private void LabelMouseLeave(object sender, MouseEventArgs e){
(sender as Label).Focused = false; // Not sure if you can set this property, no VS and I am lazy enough to search. You can ignore this handler if you may
}



对于您的HelpProvider控件,有一种类似于SetShowHelp的方法(或类似方法),您可以调用该方法并将帮助与标签相关联.

完成后,将鼠标置于标签上,然后按F1:瞧!它应该工作. :)



For your HelpProvider cotnrol, there is a method like SetShowHelp (or something similar) you can call that method and associate the help with the label.

Once you are done, set mouse over label and press F1: voila! it should work. :)


仅需注意:这是非标准的行为,这会使使上下文相关的帮助与直觉相反.普通的上下文相关帮助行为基于焦点控制和/或选择,而与鼠标位置无关.

用户直观地将鼠标位置视为 volatile :如果用户正在积极地移动鼠标并且可以立即看到鼠标悬停事件的一些视觉反馈,例如控件上的色彩效果,则它总是很引人注目.当用户使用键盘时,她或他不会注意鼠标的位置.

由于这些原因,很难期望用户了解鼠标的位置如何影响F1上的帮助. 不要这样做; 或者,放弃上下文相关的帮助,而无条件地仅调用F1上的常规帮助.

—SA
Just a note: this would be non-standard behavior which would make getting context-sensitive help counter-intuitive. Normal context-sensitive help behavior is based on focused control and/or selection, regardless of the mouse position.

Mouse position is intuitively viewed by the users as volatile: if the user is actively moving the mouse and can immediately see some visual feedback of mouse-over event such as color effect on control, it is always noticeable. When the user uses keyboard, she or he does not pay attention for the mouse position.

By these reasons, it''s hard to expect the user gets how the mouse position affects the help on F1. Don''t do it; design more expected and natural context-sensitive help based on keyboard focus. Alternatively, give up context-sensitive help and make just invocation of general help on F1, unconditionally.

—SA


您也可以考虑以下代码

You may consider below code as well

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //Make Sure Form gets the key.
            KeyPreview = true;
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            //1. Check Wether Key is F1
            //2. Chek mouse is over label or not
            if(e.KeyCode == Keys.F1 && label1.ClientRectangle.Contains(label1.PointToClient(MousePosition)))
            {
                //Open CHM file
            }
        }
    }


这篇关于在鼠标悬停在标签上的同时按F1键时,打开.chm帮助文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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