Borderless windows form with Windows 7 dragging enhancements - c#

In Windows 7, you can drag a typical window to the top of your screen and you'll see an outline of the window maximized. If you let go, Windows will maximize the form. Likewise, you can take an already maximized window and "pull" it down to restore it to the normal windowstate. I'd like to leverage these enhancements in a borderless form within my C# WinForms app.
My form is borderless so I can create a custom titlebar and minimize/maximize/close buttons. I can get my form to move by dragging the titlebar but I don't know how to plug into the Windows 7 enhancements that give me the maximize outline or the "pull down" feature.
Any suggestions? Thanks!

I did something like this in Delphi 7, years ago.
1) Form - OnCLick - capture mouse position on entire screen (maybe this link will help: http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx), save information about button pressed in private variable (example: buttonPressed = true)
2) Form - OnMouseMove - according to new mouse position, move your window
3) Form - OnMouseUp - buttonPressed = false. If cursor coordinates are in top of screen (x[0..screenW] y[0..10] ) --> maximize.
Just a hint, maybe it will help you.

Related

C# Form2.ShowDialog() and Mouse Cursor

(NET Compact Framework 3.5, Windows CE 6.0)
I want to hide mouse cursor.
So, I use Curosr.Hide()
I have two forms, Form1, Form2.
The size of Form2 is smaller than Form1.
PictureBox1 is in Form1.
When PictureBox1 is clicked, Form2 will be opened. (modal)
At this point, the mouse cursor suddenly appears outside area of Form2.
MouseDonw PictureBox1 -> Form2.ShowDialog -> Show MouseCursor
I have never done Cursor.Show()
Why does the mouse cursor appear?
Added the following
I moved Form2.ShowDialog() from 'MouseDown Event' to 'MouseUp Event'. then it is resolved. Why?
First, form show and other 'actions' usually are done with a mouse click event. That is fired after mouse down and mouse up.
If you break the normal sequence, ie show a form on a mouse down event, the GUI is in 'Mouse down/move' mode, for example to drag an element or draw a line.
As each element can show/hide the mouse cursor, the Windowing System recognizes youre Cursor Hide on the second form, but the first form still shows the mouse cursor as the Mouse Up event is not done.
If you would like to know more about the Basics, you should look at a native WndProc and how are Window Messages are handled. Programming Windows by Charles Petzold is still the bible for Windows programming.

Windows form with a transparent background that can be clicked through

INTRODUCTION
Using C# or VB.NET. I'm trying to make a form's background transparent; this form will be overlaped to other window, it will be a top-most window, so the transparent form (and its controls) must have the ability that they must not receive focus and they must can be clicked trough, this means if for example I perform a left-click on the transparent background, then the window on background of that (in the Z-order window) is the window that must receive the click instead.
Notes:
For avoiding the focus I'm overriding the CreateParams property as explained here.
For making my form transparent, I'm calling Win32 DwmExtendFrameIntoClientArea function and also using SharpDX library as explained here. But I think this really doesn't matter with the question itself.
PROBLEM
I'll show a demostration of what I mean using images. Here below is a image of a form (with no transparency, just to simplify understanding) overlapped to a window of a text editor program; note that my form doesn't receive focus. Well, the problem is when I do click on the form's background (or one of its controls) the window on background (the text editor window) still have focus but it can't receive the click.
Here is the same image of above but with a transparent form:
RESEARCH
I'm not really sure about what to investigate, so I'm going blind trying to find something useful in a trial-and-error stage by overriding the Window procedure (WndProc) of the transparent form to test related windows messages, like WM_NCHITEST or WM_MOUSEACTIVATE message as said here:
Windows form with a transparent background that cannot be clicked through
Make a form not focusable in C#
How do I create an "unfocusable" form in C#?
You can do this by sending click (mouse up & mouse down) messages to the window underneath the transparent window using WinAPI.
PostMessageA
You'll need to find the window underneath the point you require.
WindowFromPoint
You'll have to translate the position of the click events accordingly since messages are processed based on relative window position, not absolute screen position.
I actually did this quite successfully to automatically play a facebook game many years ago.
Check the RAD designer in Visual Studio.
Is the label docked to fill?
Where is the main form clickable?
The transparent color is click-though in the main parent, however, components will still retain clicks.

Form that locks UI

I've created an app in Visual C# with a Form.
I need that form must be always on top and fullscreen (of course, center).
The users must be submit the form to use computer (no Alt+F4, no ALT+TAB).
I tried to set the TopMost property to "True" and I set the form to fullscreen (but the contents remain on the top-left corner, like initial dimensions, and the user can switch between app with keyboard).
Is that possible? Essentially I want a lockscreen.
Thank you!
Regarding disabling Alt+F4:
How to Disable Alt + F4 closing form?
Regarding full-screen:
How to display a Windows Form in full screen on top of the taskbar?
Alt+Tab (and others):
How to Suppress task switch keys (winkey, alt-tab, alt-esc, ctrl-esc) using low-level keyboard hook in c#
Regarding Ctrl + alt + del, it's not possible to disable. However, as stated elsewhere, you may want to consider IE Kiosk mode.
https://support.microsoft.com/en-gb/kb/154780

Responding to mouse cursor position in a Windows 8.1 app

I have a Windows 8 application, and I need to detect when the mouse is at the bottom of the screen because my application has a CommandBar, and I would like to open it when the mouse is at the bottom. I already have swipe gestures that will open it when the user swipes, but now I have an added requirement for when the user does not have a touch device and instead must bring the mouse to the bottom of the screen to show my CommandBar. I am used to WPF's style of MouseMoved events, but unfortunately these are not available in Metro applications, so how can I get the mouse position or at least detect that the user has brought the mouse to the bottom of the screen? I have tried searching about this, but I couldn't find anything...perhaps I am missing something?
As Chue X said the standard way to open the app bar by mouse is right click.
Windows Runtime apps use Pointer messages for all pointer input: Mouse, touch and pen will all generate PointerPressed, PointerMoved, etc. You can examine the Pointer event args to see which type of input it is in the PointerPoint.PointerDevice.PointerDeviceType.
There are slightly different versions of the Pointer events on the CoreWindow (with full window scope) and on the xaml UIElement (scoped to the element). You can use either in a xaml app. For your use either would work. They give essentially the same information.
Responding to mouse interactions (XAML) http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994936.aspx
Here's the code I used to achieve this behavior from any OnPointerMoved event handler:
... OnPointerMoved(PointerRoutedEventArgs e)
{
PointerPoint point = e.GetCurrentPoint(page);
if (point.Position.Y > page.RenderSize.Height - 5)
{
page.MainMenu.IsOpen = true;
}
}

How to make close(X) button to invisible in Windows forms but min & maximum button should visible? [duplicate]

This question already has answers here:
How to hide only the Close (x) button?
(5 answers)
Closed 9 years ago.
I got answer for disabling the x button in windows forms but is it possible for completly make hide/invisible the close(X) button and move the maximum button to close(x) btn position and minimum button to maximum button position in a form. without creating custom/user control/new forms
I don't believe you can hide it without hiding/removing the entire control box. The best solution would be to disable it if you don't want a using pressing the (x) button.
#Andy is correct, it's not possible. Those buttons are located in what's called the Non-Client area of the window—meaning that part of the window is (more or less) controlled by Windows and not the program "hosted" in the Window. Note that disabling the Close button also disables the Window's system menu (or Control box menu).
What you may want to do is hide all the title bar buttons and create new buttons on your application form that minimize and maximize the application.
However, I would ask why you feel the need to move the buttons? If you must move the buttons or have a different design for them, I know applications like Trend Micro anti-virus "skin" the window by providing an image for the application window and create custom (a/k/a owner-) drawn controls. They also "skin" the Non-Client area, effectively designing how/where they want the title bar text displayed, the minimize/maximize buttons, etc. But that's a lot of work and generally doesn't look as polished (in my opinion). Plus, people are just plain used to the standard Windows form, which is why it's "standard".
One more thing to think about is using WPF. You can basically redefine the Window template, thereby changing the look and feel (and position) of, generally, non-client area buttons such as the Minimize and Maximize buttons.
You have to ownerdraw the thing,
Hide all status bar setting FormBorderStyle to none
Place a Panel At the top of the form using Dock Top
Create the buttons you need (Minimize, maximize)
Make the Panel Title bar that grags the form Make a borderless form movable

Categories

Resources