Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I´m trying to implement AutoHide function to my C# winForm appBar for more then a week and I still dont have a solution. Now I have an idea how to do it diffrent then via SHAppBarMessage (cause I don´t know how to use it for autohide), but I´m looking for a way how to get if mouse is hover the form even if form is visible = false or hide(). Do anyone please know some example? Thank you very much, Blaato.


What I have tried:

I´m trying nothing, cause I don´t have any idea.
Posted
Updated 9-Jun-17 3:11am
Comments
Ralf Meier 8-Jun-17 12:18pm    
I'm a bit confused ...
If the Form isn't visible ... how could the Mouse be over it ? You should give much more information ...
Blaato 8-Jun-17 14:50pm    
Even if Form is not visible, it is still have a location and size. It still exists, just it is not visible. So now I´m thinking about mousehook, but I had never work with it , so it will be one try by another. But if you know better way i will be really gratefull.
Ralf Meier 9-Jun-17 1:42am    
Why i'm confused :
Normally you have severall Forms in one Project (3,4,5,6,7 ... etc.)
Often serverall Forms are located on the same Position (with the same size).
So ... how do you want to decide over which of those unvisible Forms the Mouse is located in this Moment ?
And ... for what Behaviour do you need this Information ?
Blaato 9-Jun-17 3:21am    
Like I wrote before, it is an appBar, so now we working only with one Form, no other neeeded. The mousehook is a solution like I said.
And now why I need that information.. Like I said, I'm trying to make my appBar autohide, but I dont know how to do it via SHAppBarMessage, so I decided, that I can just unregister appBar and let it on same position of the screen and make it hidden. And when mouse is hover the form on for example 0 -> 2 top pixels of the form, it can be visible again. So it is a workaround for autohide function for an appbar.
Ralf Meier 9-Jun-17 6:29am    
So you should write what you mean ...
Your AppBar (I don't know it) seams to be a Control which you set to unvisible.
Now (if your control isn't visible) you want to show it (make it visible) if the MousePosition is in it's location - am I right so far ?

1 solution

Put this method into the code of your Form :
C#
 protected override void OnMouseMove(MouseEventArgs e)
{
    if (button1.ClientRectangle.Contains(e.Location))
    {
        button1.Visible=true;
    }
    else
    {
        button1.Visible=false;
    }

    base.OnMouseMove(e);
}


In my Sample I used a Button to Show and test the effect. You only have to replace 'button1' with your Control ...
 
Share this answer
 
Comments
Blaato 12-Jun-17 4:56am    
Firtsly, thank you very much for your code. But this cannot work, for my case, becouse in this example, you listening mouse on your Form, which is active and set visible property on it's child control - button. But when your Form is inactive (not visible), you cannot listening mouse position on it like that.
Ralf Meier 12-Jun-17 6:18am    
I referred to your comment where you wrote that you only have one From and the Bar is a Control on this form.
If you don't have a Form (or the Form is invisble) you can't work with any Form- or Control-Event (as I wrote before) ...

But, what you can do is :
- set the Form-Size to the Size of the Control and locate it to perhaps the Top-Position of your Screen.
- work with the Form-Opacity (set it to '0' if you don't want to see the Form and set it to 100% if your Mouse is over it ...
Blaato 12-Jun-17 6:53am    
I never said that I'm workinkg with a control on my form. I'm really sorry, AppBar is a known thing and I supposed that everyone knows it. It is the same as a Windows Taskbar like I wrote before. But nevermind, i will find my solution. :)
You have to know appBar for finding a rigth solution, but really thank you for all of your helps.
Form opacity is one of my workaround, but it is not perfect - in case, that my appBar is on the top edge:

Form width -> 2pixels
Opacity -> 0
Register appBar to windows -> top edge of the selected screen
and listening mouse hover
Ralf Meier 12-Jun-17 7:45am    
"AppBar is a known thing and I supposed that everyone knows it."

As you see - not everyone knows it ...
Blaato 12-Jun-17 7:47am    
Yes, seems like that. :)

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