How to draw rectangle on screen showing where appbar window will dock - c#

I'm working on a class that descends from the WPF Window class that implements the Application Toolbar functionality available in the Window 7 + shell (that is, it calls the Win32 SHAppBarWindow to dock to an edge of the desktop and undock). The idea is that you can drag the window around the screen and when it is within some distance of a desktop edge, it docks itself.
Because of the need to call the Win32 SHAppbarWindow function, and because working through WPF events is just not helpful, I've written a window procedure that works at the Win32 level & is hooked in using the HwndSource.AddHook method. This procedure gets called first and processes anything it needs to process, and passes the rest on to WPF.
I've been working on the dragging logic and I'd like to give the user a visual indication that the window could dock itself to the edge it's closest to, without actually docking it. To that end, I'd like to display a transparent rectangle with a dashed border the size that the window would be after docking in the location it would be. If the user releases the left mouse button at that point, then the window would actually be docked at that edge. Once the mouse is moved away from that edge, the rectangle would go away.
I know how to compute the rectangle's size & location. But how do I display the rectangle? I'm pretty sure I'd have to do it with GDI32 calls, as the target area is outside the window's nonclient & client areas. But how would I draw the rectangle, without messing up the other windows that might be in that area?

Related

How to make a winforms scrollbar wider using c#

This program uses winforms and c# (no wpf). I have a panel with buttons on it and getting it to scroll is no problem. However, when the program is on a hi-resolution touch screen -- like a Surface 7 -- trying to touch in the exact right spot to get it to scroll is hit and miss. I've searched and have yet to find a way to make the grab area (so to speak) of a vertical scroll bar wider so that when you touch the screen, the control actually picks up the event. Any ideas on how to do this?
If your application is DPI unaware, then it is enough to set the scrollbar width to SystemInformation.VerticalScrollBarWidth.

Can I stop UWP app from being dragged beyond its bounds when keyboard is shown?

I have an application using Xamarin.Forms Running on UWP
When the keyboard is visible I am able to drag the application around to see the rest of the screen. But I can also drag it beyond its bounds, which shows a black background. See screenshot below:
Is it possible to change the colour of this background or stop the application from dragging beyond its bounds when the keyboard is visible? As this behavior is confusing to my users

Windows Form app that takes up the top area of a screen?

I'm trying to create a windows form app that "owns" the top area of a screen. Think of it as just a rectangular form width = screen size and height = 20px or so. The app would always be on top and would be borderless (i.e. FormBorderStyle=none). The questionable part, for example, if a user maximizes a window like chrome or some other application, it should treat the bottom of this windows form app as the top of the screen. This way since the form app is always on top, it doesn't cover up any of the maximized application's window.
Any clues on how to do this.. can it be done with windows forms? The only questionable part is how to "own" a portion of the screen.
Let me know if clarification is needed. Thanks in advanced.
What you need is to set the Screen.WorkingArea which is readonly you should use PInvoke to achieve this you can find your answer in this thread
To get the working area of the display you can use Screen.WorkingArea property

About labels in windows forms

I have a program that currently launches a winform in full screen, hiding the task bar.
If I manage to keep fiddling with the cordinates to get a text label to sit in the bottom right corner of the screen. will it always appear there regardless of what size screen or computer is running the program?
In the label properties, set the Anchor from Top Left to Bottom Right.

Making a graphical element "dock-like"

Specifically, what I am try to is overlap my element on top of everything, including the desktop, similar to the taskbar in Windows. I have a Windows Form Control that looks kind of like a tab. its like 50px wide by like 150px in length. What I would like to do is have that control appear in front of all windows, including the desktop itself. I say "dock-like" because I belive docking pushes windows over (so if my tab was docked, it would push any full screen application window over 50px), which is not what I'm trying to do. I want my tab to overlay on top of everything. The closest example I can think of is Winamp. Winamp can dock to the top of the screen and it is always on top of any application.
how can do this in C#?
System.Windows.Forms.Form has a property, TopMost, which will cause the form to stay on top of other windows.
The "snapping" behavior of Winamp can be implemented by using the Move event of the form--when the form is moved close enough to the edge of the screen, programatically set the position so that it's on the edge.

Categories