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
Related
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.
I have done flyout window similar to win7 battery meter. It is behaving just like built in one except when it is shown via notify icon who is located on NotifyAreaOverflowWindow aka notify overfow area that window autohides itself after some time while it should hide only when my flyout closes. The only difference that I could spot with spyxx that after some time overflow window simply sends itself an WM_SHOWWINDOW wp:0 lp:0 message.
How can I prevent the overflow window from autohiding while my flyout is active?
Image 1: Test flyout shown after click on notify icon which is located on overflow area + couple seconds of user inactivity.
Image 2: Battery meter flyout shown by clicking on notify icon which is located in overflow area + 2 mins of user inactivity.
You should call
NotifyWinEvent(EVENT_SYSTEM_MENUPOPUPSTART, Handle, OBJID_CLIENT, 0);
before you show your window and call
NotifyWinEvent(EVENT_SYSTEM_MENUPOPUPEND, Handle, OBJID_CLIENT, 0);
after you hide it.
Flyouts are no different from any other window.
If I'm understanding your problem, which is that the windows disappear over time, then the solution is quite simple. Do not use whatever NotifyAreaOverflowWindow is. Instead, create your own window, with the appropriate properties (no control box, no max/min buttons, no title text, etc...). Because it's likely out of your control to set the duration of the class/object you're using. It's likely designed for single-notifications, and not something moderately useful ;).
Plus, you'll be able to do fancy things as desired without running into anymore issues.
The following tutorial goes in great lengths on how to position it so perfectly:
http://blog.quppa.net/2010/12/09/windows-7-style-notification-area-applications-in-wpf-part-3-taskbar-position/
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
I want to prevent my desktop application from being maximized. It should not become maximized by any means - by double clicking on title bar, or by clicking Windows + Up arrow on the keyboard, etc.
-> I disable both the MaximizeBox and MinimizeBox.
-> I also set the MaximumSize and MinimumSize for my WinForm
Still when I press Windows + Up arrow, my win form Shifts to top left of the screen, I mean it gets maximized.
So please tell me any way to prevent this thing happening...
There are actually two completely separate issues at work here. Granted, they look basically the same from a functional perspective, but from an implementation-model perspective (as Windows itself would naturally use) they are unrelated.
As others have answered, you can prevent your form from being maximized by setting its MaximizeBox property to false. This removes the WS_MAXIMIZEBOX style on the form's underlying window, which prevents the window manager from allowing the window to be maximized. It disables the maximize box on the window's caption bar (the one between the minimize box and the close box), disables the "Maximize" option on the window/system menu, and any other methods of maximizing a window that I may have forgotten.
However, this has nothing to do with the Win+↑ keyboard shortcut, which invokes Aero Snap the same as would dragging the window to the the magic position sat the edges of the screen. The window manager, whether as a result of a bug or a feature of Aero Snap, still allows you to effectively "maximize" windows that should not otherwise be maximized. Setting the MaximizeBox property doesn't affect this, so if you truly want to prevent the user from changing the window's size this way, you will need to disable Aero Snap's effect on your window.
Unfortunately, there's no method (at least, not to my knowledge) of programmatically disabling Aero Snap on a per-window or per-process basis (also see this related question). If the user has Aero Snap enabled, you can assume that they want that behavior and applications aren't supposed to tamper with it. The only thing you can do is completely disable resizing your window. In WinForms, you do that by setting the FormBorderStyle property to one of the following: FormBorderStyle.FixedSingle, FormBorderStyle.Fixed3D, or FormBorderStyle.FixedDialog. If you still want your window to be resizable in other ways, you will need to write the code to handle that manually, which is not a particularly easy task.
Thus, I encourage you to very carefully consider whether this is really necessary. All other non-maximizable windows accomplish this simply by setting the MaximizeBox property (or doing the equivalent in their UI framework), which means that they can still be effectively maximized via Aero Snap. If this works for everyone else's windows, including those that are part of Windows itself, it should probably work for you.
The form has a property called MaximizeBox - set this to false.
In regard to your second question, check out this question and it's answers for the best ways to implement keyboard shortcuts in WinForms.
this.FormBorderStyle = FormBorderStyle.FixedSingle;
That line of code will prevent the user from re-sizing the Window.
In addition to that you hide/disable the maximize box and that should do what you asked.
To disable the maximize box use this
this.MaximizeBox = false;
To hide the maximize box use this as well
this.MinimizeBox = false;
If Maximize and Minimize are set to false the buttons disappear.
Setting the MaximumSize equal to the Size (or some size) at least stops the windows from going full-screen. It still snaps to the top left corner but it's still a window at least and looks right - like it's Windows being stupid instead of your program.
You can prevent the windows snapping to the upper left corner by setting:
private void toolbox_Move(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
}
in the move event of the form.
There is a property of the Form class named "MaximumBox" you have to set False in the properties window of your form... This actually will disable the form from being maximized by any way... Also if you want to control your form sizes you can work with such properties as "MinimumSize, MaximumSize" setting their values at your discretion or creating an event handler for the MaximumSizeChanged and MinimumSizeChanged events...
You can try to RegisterHotKey Win+Up if your window or application is activated and unregister this hot key if it is deactivated. You must catch the hotkey and return appropriate value to prevent further processing.
Look at WM_ACTIVATEAPP, WM_ACTIVATE and WM_NCACTIVATE. The first can be used if you want to disable the Win+UP for all your windows.
Set formborderstyle to fixedsingle
Maximizebox=false
Set the maximumsize to the size of winform's default size
Ex: if size(646,385) then set maximumsize(646,385)
One thing you can do is set the MaximumSize and MinimumSize in the same value but not 0,0.
It's easy easy! Apply the folling code to maintain window's state to normal when a resize event is triggered.
protected override void OnResize(EventArgs e) {
base.OnResize(e);
WindowState = FormWindowState.Normal;
}
I have created a taskbar using tabcontrols which works similarly to the Windows taskbar.
I want to make my own taskbar fixed on top of the windows.
It should not be movable, resizable, and it should be "docked" to the top.
I have not tried to do this, but my first attempt would be the following:
set form to be 'TopMost'
set border to 'None'
set Location: (0,0), Size(Screen.Width,H), where H is the Height you want your form to be
set 'ShowInTaskBar' to false
Something you might consider: how will you handle multiple screens?
You'll likely want to add a context menu allowing you to exit the application, since it won't have the normal system buttons. Also, you might consider what happens when the user presses ALT-F4: will your program close? If not, you'll need to add some code in the FormClosing event handler to cancel closing.
Hope this sets you in the right direction!
A long long time ago Jeffery Richter demonstrated how to do a true taskbar in a sample called AppBar (I've used it myself as a boiler plate), so here are some pages that may be of interest:
http://www.google.com/search?q=Jeffrey+Richter+appbar+c#