How to make a form behave like windows taskbar using c# - c#

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#

Related

App opens maximized when it should not

I have a C# winforms application with a fixed-size starting dialog. After making some changes entirely unrelated to this form, the form now opens maximized, filling the entire screen with the actual content still at the regular size in upper left corner. Dragging the title bar down a bit with the mouse causes it to restore to its appropriate size.
The form has
MaximizeBox = False
StartPosition = CenterScreen
FormBorderStyle = Fixed3D
Does anyone have any suggestions what might be causing it to open maximized, and how to stop it?
Edit:
WindowState = Normal
is also set.
Edit 2:
I found the problem. My update routine was shutting down the original process so it could be updated (inappropriately, but that is a different bug), then restarting it with code I had borrowed from elsewhere, and part of that restart code was:
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
Thank you for the assistance. Though no direct answer was given (nor expected with the spotty information), it did point me in the right direction.
The Window being Maximised is normally set on the forms "WindowState", Light Reading. You need this to be set to WindowState.Normal. It's possible someone's set it to maximised in the designer? or somewhere else in the code. the 3 lines of code you have shown are not the problem.
Edit:
You need to do some investigation if you cant give us code from your form, Hook into some resize events, and see what's triggered it off. Forms dont just start up maximised unless they're told to and maximizing a window triggers a resize event.

Disable NotifyIconOverflowWindow autohide

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/

Switching top-most form without flickering

I'm developing a magnifier in C# .NET (using WindowsForm) that shows a top-most click-able through form. This top-most window shows an specific part of the screen.
The problem I'm having is that to take the screenshot I need to Hide() and Show() the form (otherwise I would take a screenshot of the magnifier) and this creates an annoying flickering in which the magnifier disappears and rapidly appears again.
How could I take a screenshot of the Desktop without hiding/showing the form?
Is there another approach/workaround?
Thanks.
Use the form's Opacity property. Set it to 99% in the designer. When you are ready to take the screen shot, set it to 0, make the shot and set it back to 0.99.
The change is instant, no need to wait and no flicker or repainting. Do not restore it to 1.0, that flickers.
Do beware that you remove the "Hall of Mirrors" effect from the magnifier. Bit of a loss :)

Preventing Winform from being maximized?

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;
}

Implement sticky overlays in .NET

I'm looking for a nice way to render overlays over a native Windows form not owned by myself preferably using a library available for .NET (WinForms, GTK#, ...). Precisely, I'd like to display a few labels or text boxes at a given location on the window.
Device Context & System.Drawing: What I'm currently doing is drawing directly onto the other windows' device context, which causes flickering, as parts of the other application are redrawn in unpredictable intervals. I therefore would have to catch its WM_PAINT event using hook magic, but that's actually not as far down as I'd like to go unless there's no simpler way.
Transparent window overlay with visible child labels: another technique I tried was creating a Windows.Forms.Form with the other windows' size, using TransparencyKey to make only the children visible. This seems pretty hard to get correct, as I don't want the window to be the upper-most one but only exactly one Z-level above the foreign window. The upside would be, that I could add more behaviour to it, as I could actually handle click events, etc.
How would you implement it / deal with the problems in the two techniques described above?
Definitely go with the transparent window approach as that should be simpler to implement. Creating a transparent form is very easy. You already know how to use the TransparenyKey to get the background to not drawn. Also remove the border from the window and remove the min/max/close buttons so you do not have any chrome showing.
Create your window as owned by the window of interest and it will always be on top of the target and act like a modeless dialog. I.e. it is visible only when the owning window is visible.
Thanks for your answer, but I'm still a little confused. How exactly would you set the owner of a window to anything not owned by your own application? I guess that's not even possible when the other application is unmanaged, is it?
Edit:
I now got a little step closer. The example code is in Boo.
[DllImport("user32.dll", SetLastError: true, CharSet: CharSet.Auto)]
public def SetParent(child as IntPtr, parent as IntPtr):
pass
def createAttachedForm(parentHandle as IntPtr):
f = Form()
f.Text = "My overlay"
f.Show()
SetParent(f.Handle, parentHandle)
Application.Run(f)
Now only the TransparencyKey thing doesn't seem to work. Instead the form is completely invisible when the value is set.
Setting the owner of a form can be done with
Form.Show(IWin32Window w)
where w exposes the Handle to the parent window.

Categories

Resources