Prevent other windows from overlapping my form? - c#

I have a form that is on the 2nd monitor and full-screen. I want to prevent all other windows from accidently being moved into the second screen and over lapping my form.
I also need to make sure that if a window gets moved to the other window and I use topmost, I don't want the other window to get lost.
I want to make the 2nd monitor( or my app ) un-overlappable. Not necessarily make it the topmost app.
This is a c# form.
What would be the best way to do this?

Form.TopMost property:
A topmost form is a form that overlaps all the other (non-topmost)
forms even if it is not the active or foreground form. Topmost forms
are always displayed at the highest point in the z-order of the
windows on the desktop. You can use this property to create a form
that is always displayed in your application, such as a Find and
Replace tool window.

Related

App has too many tabs opened in the task-bar

I'm making a WinForm app in C# (Visual studio) for fun. I came across a low-priority problem. It doesn't affect how the app works. But...
On the starting page, I have a button to open a Form1, inside Form1, there's a button to open a Form2 and so on.
At runtime, when I open a form, its parent form does not close and every form is a separate tab in the task-bar. As the layers grow, I'll have more-than-acceptable amount of tabs down there...
Is there a way to have only 1 tab?
I've tried:
Adding a parentForm.close() line when opening the form, but that was bad.
Instead of creating another form, putting everything in a panel, and bringing out another panel using code, but if there are too many layers, the code gets ridiculously long.
There has to be a simpler way right? Please shed some light.
Yes, you have a property in every form called ShowInTaskbar which is true by default. You can change that in the form properties under Window Style section or changing it by code manually:
Form2.ShowInTaskbar = false;
Form2.ShowDialog();
Configure to false all forms but the first one in order to achieve your desired behaviour.
Make sure your opened forms are dialogs or you are put them on top so user can never get in the situation where the form is behind and they cannot close it.
Anyway, with a proper form parenting configuration (if it fits your needs) you won't need this, as children forms won't appear in the taskbar.
If a form is parented within another form, the parented form is not displayed in the Windows taskbar.
Make sure you check the MSDN Documentation about this.

Is there a way to keep all windows in focus within a Windows Forms application?

I have an application that some times requires the user to have two forms open at a time. I have the main 'home' form window, but also a calculator form window. It isn't a normal calculator so I would like the calculator to stay within the one application.
When filling out the main form, the calculator is needed to work out some data to input. Only problem is, when calculator.ShowDialog() is used, the main form loses focus. The calculator is opened to the right of the main window. So ideally, I would have which ever window is clicked, gain focus.
Just use form.Show() instead of ShowDialog
Me thinks that you can add Code line calculator.Activate();

How to keep a window inside your application only?

I'm writing a WPF application which has a main canvas area, where the user can open a number of windows, drag and drop them and generally move them around the application as he or she pleases.
What I've done so far basically opens windows using the Show() method, and I have hidden them from the taskbar. However, when the main application is minimised, the small windows which have been opened all appear on the desktop. What I am lookign for is basically a way to keep the windows contained within the application.
Is this possible?
Yes but you need to design some infrastructure to replace what MDI used to do ( though often quite badly)
So when you open a new window in your app, add it to a list.
When it closes, take it out
When your main app is minimised, minimise all the windows in the list as well.
You can also trap child window move events and keep them in bounds, take the children with you when the main app moves. Docking, cascade, tiling...
Key bit it to get this list of managed child windows going.
What you want to do is called MDI.
WPF MDI

Menu shortcuts and MDI in Windows forms

After I modified my application to the MDI application (main form became an MDI container), all of the shortcuts, which were specified int the main menu of the original form, are no longer works. What can I do in order to "turn them on" again?
The only thing that comes to mind is that you need to set the mdiparent property of any child form before you show it. You could have missed this when you switched the main form over.

WPF Child Window - Remote Desktop Session

We have a WPF application that has a main window, and 1 child window shown by ShowDialog with ShowInTaskBar set to false.
We save their positions on close, and set Window.Left and Top when re-opened.
Problem is, when you remote desktop into a computer with multiple monitors and then open the child window with a saved position offscreen, there is no way to bring it onto the single monitor.
Is there a something we can change on the child window to make windows handle this issue? The main window doesn't have this issue (I thought it might be related to ShowInTaskBar or the fact it is the main window).
Is there a better way for us to store the window location?
There is no default way within WPF to access any available screen other then the primary screen.
WPF does have SystemParameters.PrimaryScreenHeight and SystemParameters.PrimaryScreenWidth to work with the primary screen however to get information on screens excpluding the primary you would have to make use of the System.Windows.Forms.Screen class.
If you went the System.Windows.Forms.Screen class route you could save relevant data about the window based on the screen at which it resides. Then upon reading the values in you can force the window to the desired screen based on the number of screens residing in the System.Windows.Forms.Screen.AllScreens array. It gives you flexibility for placement as you can take advantage of all available screen within the system versus just the primary.
EDIT:
If you are not concerned with getting the screen information in a modular manner (information per screen versus the aggregate of all available screens) and do not want to make use of the System.Windows.Forms.Screen class you can make use of the SystemParameters.VirtualScreen* properties which will provide the aggregate of available screens.
It should always be possible to get any window back on screen. The following steps hook the currently active window to the mouse cursor:
Press Alt+Space to open the system menu
Press M for 'Move'
Press the right arrow key
now move the mouse

Categories