I need to create a application which is similar to those we will get when we buy a laptop. It will be visible only when the mouse pointer reaches the top of the window. So how can I able to do this using C# 4.0 ? http://www.notebookcheck.net/uploads/pics/win2_12.jpg this link u can see the application. I need to create such type Any idea pls share. Thanks
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I suppose there are several different ways to achieve this effect:
- You can place part of the window of your application above the visible screen, so only a part of it is visible (let's say you can see only it's bottom). Then you need to handle events when mouse enters (
MouseEnter
) and leaves (MouseLeave
) the form to move the form up and down. - You can use a background thread to call
GetCursorPos
method at a set interval (i.e. each 500ms) second to check where currently the mouse is. See this link for more information about it and a sample code: http://www.pinvoke.net/default.aspx/user32.getcursorpos. (If you need only to check the mouse position, you can use a timer to simplify you application.)
回答2:
When you hit what's possible with C#, you can always start invoking native code - such as the windows API. Since you don't ask a specific question, I'll leave you with:
- Position your app where you want it to appear and hide it.
- Capture mouse position with windows api (see this SO answer)
- When mouse is at screen corner / top, etc; make your app visible.
Now make sure all this works with dual screen setup, and you are done.