C# Autohide form - c#

I've a winforms app that "docks" to the taskbar
I'd like to autohide the form and make it appear only when the mouse goes near/over the form
any suggestions ?

Install a global hook onto the mouse-move event and check to see if it is within the form boundaries. Should work even with the form hidden. If not just store the location as a rectangle and check against that.
Code for a simple and handy global hook implementation can be found at:
http://www.codeproject.com/KB/cs/globalhook.aspx
I've used this method to create "hotspot" functionality to a user desktop.

I'm not sure it is exactly answering your question, but there is a sample of this on Codeplex...
http://remoteaccessmonitor.codeplex.com/
Browse the source code and check out the MinimizeToTray.cs file - it has examples of pop up messages when hiding and I think its default behaviour is to re-appear on click (although I imagine this could be changed).

You could.
Poll mouse coords until it's within a certain radius of your app.
Position an invisible, always-on-top form above the docked app and have it fire a MouseEnter event.
That's all I can think of really. Either.

Related

Dynamic form with resizing in C# .net

As a learning project in C# .net I am re-creating a Gnome 3 plugin for seeing who of the streamers you follow on Twitch is live. I have the settings form done, I am now working on the interface that is viewed from a click on the taskbar.
This is a rough image of what I want the interface to look like. When two or more streamers are live the interface would add another block and resize the form vertically similar to the menu for selecting a Wifi network in Windows.
What would be the best way for me to complete this?
My current thought is to maybe create a custom control and just place those inside a FlowLayoutPanel with some kind of code to change the vertical size of the form to match the added entries. Maybe this can be done without a custom control and be done with code inside a FlowLayoutPanel? I'm not too sure.
Ideally I would also have a click event in the panel for each streamer so I could then open a browser to their channel. A slight highlight would also be a plus (maybe change the background colour based on mouse hover).
Thanks in advance for any suggestions!

How to create a transparent window that both captures mouse events and allows them to pass through

I've tried searching for the answer to this issue but I've been unlucky trying to find it.
From similar questions on here I've been able to make my transparent window receive mouse events, but then the other applications running behind it don't get any mouse events (Set the background of the window to #01000000 (mostly transparent)).
Or the alternative I've also achieved: the transparent window gets no mouse events and they are all passed through.
Is there a way to combine these 2 and have a transparent window that both interprets mouse events and passes them to whatever is behind it? My end goal would be to display a *ping* graphic on the transparent window (which is the same width/height of my desktop resolution) any time the mouse is clicked on the screen while I'm using other applications.
Further edit:
I have a Canvas in my WPF window. It has MouseLeftButtonDown as an element which calls a method in the behind-code. This method does not seem to get called when I use the solution that I linked, or when I simply set the Window and Canvas to Transparent or #00000000.
I think a better approach would be to use windows hook to catch global mouse events, and simply let your application discard mouse hit tests. As far as I know, Windows hook are not directly available in the .NET framework, but they are PInvokable.
Microsoft provides a pretty straightforward guide for this here.

Detecting UserControl User Custom Cursor, and Getting Callbacks

I am creating a fullscreen demo application (demo = not production, so hacky code is okay though not preferred) for the Kinect SDK. The application hides the Windows cursor and shows a custom hand cursor which is defined as a object.
What I would like to do is create a custom UserControl (let's call it "HoverControl") that can detect when the cursor object is over it and then send back timer ticks, allowing the cursor object to update in some way (showing the user that something is about to happen).
The behavior is pretty much a copy of the Xbox 360 Kinect behavior. How things look will just be a little different.
How can I detect with the cursor object is over a "HoverControl" and have receive a callback from the HoverControl?
Thank you for any help or suggestions!
CLARIFICATION:
I am not currently moving the Windows cursor, so MouseEnter doesn't fire.
You can use your own cursor by making one using Online Cursor Maker. See this website on how to set it. Then you can use MouseEnter and/or MouseLeave.
Coding my own cursor in XAML, and creating a UserControl out of it, I set up a timer inside the control to perform a hit test for certain buttons (again, their own unique UserControl type) around my interface.
I ran into one issue with the hit test, which I was ultimately able to solve and detail in the following post at MSDN:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a8cdb265-21cc-4fd0-b40d-e6778b659852

Handling Right Click/Left Click of Task-bar Button in c#

I have a form (having Taskbar button shown in Taskbar) and I want to handle left/right clicks of this Task-bar button. I searched everywhere but could find the right answer. There are some related queries posted in stack-overflow as well:
Using wndproc in C# to minimize form on leftclick of taskbar
How to Detect Right Click on the Taskbar
But, nobody seems to have given a proper answer to "How to do" it?
Is there any pointers or code snippet how to do it?
Please note that I am talking about Task-bar app button (please don't confuse with Systray menu or Notification area). I have explicitly stated it because I have seen this confusion several places.
Your application doesn't get a say in how the task bar button is handled. The task bar is owned by windows, and is used by windows to control display and positioning of your application's windows. Basically your request is out-of-bounds in the windows playground.
Sorry.
what you can do is to use TaskbarManager out of the ApicodePack library
Windows 7 Taskbar C# Quick Reference
where you are able to handle such events.

C# WPF DragMove without Window_LocationChanged()

I implemented something in Windows Forms similar to DragMove but with boundaries set to 10 units of the margins of the primary screen.
When switching over to WPF I found this thread to be useful in achieving the same result.
However, since this is a post-move event, what happens is that if my window is dragged beyond the boundaries I set, it "jumps" back. I would like to avoid this effect as it looks terrible.
Is there a simple way to avoid the window to be moved outside a given area without using the LocationChanged event? I basically want to restrict the movement of the window before it happens.
These this are very hard to achieve with WPF because it does not expose the base Win32 functions and events like WinForms did. I had a project where I needed to to resize a window and I had to use PInvoke SetWindowPos to do this in a normal manner.
AddHook may help you, but this will still be quite difficult. See http://www.wpfmentor.com/2009/01/how-to-get-hwnd-and-hook-into-wndproc.html and http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndsource.addhook.aspx for more information.

Categories