Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted
Updated 12-May-11 18:18pm
v2
Comments
Sandeep Mewara 13-May-11 0:17am    
K1? ... F1 I think... typo.
Pora2 2-Jun-11 23:36pm    
Thanks! My question is answered.

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
}


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. :)
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 13-May-11 0:47am    
That should work, my 5, but does it makes full sense?

Please see my answer.

(I fixed your typo: "Focused", if you don't mind)

--SA
dan!sh 13-May-11 0:55am    
No it does not. I guess OP should be looking for a tool tip rather than help control. May be he has a justification for this.

BTW thanks for updating.
Sergey Alexandrovich Kryukov 13-May-11 7:00am    
Well, that's the different story. I would voted for this useful idea if you post it as an alternative solution.
--SA
Prasanta_Prince 13-May-11 1:25am    
Good job 5 from me.
Rojeh 13-May-11 4:08am    
good job
my 5
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
 
Share this answer
 
v2
Comments
dan!sh 13-May-11 0:56am    
All valid points. Have a five. :)
Sergey Alexandrovich Kryukov 13-May-11 1:14am    
Thank you.
--SA
Rojeh 13-May-11 4:06am    
100%
my 5
Sergey Alexandrovich Kryukov 13-May-11 4:46am    
Thank you, Rojeh.
--SA
Prasanta_Prince 13-May-11 4:52am    
Good one.
You may consider below code as well

C#
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
            }
        }
    }
 
Share this answer
 
Comments
Rojeh 13-May-11 4:06am    
good one, my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900