WPF Child Window - Remote Desktop Session - c#

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

Related

How to set a maximize limit for windows form

I have a project which has several forms which are connected to a SQL database (read and write). Apart from the parent form, each form starts in center position and in the size I set for it in the properties (which apparently it is considered by the system as the minimum size). When I click the maximize button it goes full screen and that is my problem.
I want the child form to be just a little smaller than the main form (so that I can see the header from behind). When I write my preferred maximum size in properties field it just doesn't work.
I used the first solution written here: Is it possible to set the Maximum Width for a Form but leave the Maximum Height Unrestricted?. It gave me a restriction for the maximized size. However, it not only makes the form get out of center, but as soon as I click on the form it goes back to minimum size.
The other issue is that my project is suppose to run on more than one computer with different resolutions. So, i don't think giving it a specific size would help.
Bottom line is, I want the size of my child form to maximize to a limit just a little smaller than the parent form which is full screen.
Can anyone help me?
It seems you're trying to create a Multiple Document Interface (MDI) style application. This style isn't very common any more, but here are some examples on how to do so.
The StackOverflow example you gave uses the MaximumSize property. That property doesn't apply when the user clicks the 'maximize' button at the top right. It is used for when the form is configured to allow resizing (by grabbing the handle at bottom right). Maximize functionality will either fill the full screen, or for MDI applications, the entire MDI parent window -- and it's always been that way.

Clone window across all screens

I'm using dualview setup in my OS (1 view extended across 2 screens). In my winforms application I can move particular window to secondary screen, e.g.:
foreach (Screen s in Screen.AllScreens)
{
if (!s.Primary) {
myform.Bounds = s.Bounds;
break;
}
}
Everything is fine, when I can see this secondary screen. If I see it, I'm able to use any functionality such window form provides, e.g. I can close it by clicking the appropriate button.
But what if I cannot see this secondary screen, e.g. this is a projected image displayed on a wall in another room ? I cannot use my forsaken form then. How to cope with such uncomfortable situation (moving to the same room is not an option) ?
What I want is to make an exact duplicate of such form to be shown both on my primary screen and the secondary one. I'd really like to have multiple instances of the same window, exact copy, where one instance reflects changes at the other one and and vice versa. I could control the secondary screen (react on some popup information, etc) using the main one placed in remote location. I have no idea how to implement something like this in .Net with the usage of winforms. How to do it ?
BTW: If this is hard to achieve, what can be done from the conceptual point of view ? I know I can define some keyboard shortcuts but this is not what I'd like to have. Any ideas?
Conceptually, you could use a second window (call it a "Mirror form") to duplicate the primary form. Capture the screen for the primary form and display the captured portion on the mirror form.
That part is the easy part. If you want to be able to actually interact with the Mirror form, you'll need to capture all user input such as mouse move, hover, click events, and keyboard events and replay them onto the main form.
You might be able to do that with the event handlers on the Mirror form by capturing all of them and replaying them them on the primary form. However, I'd look into capturing the messages on the mirror form. That is probably more comprehensive and probably a cleaner way code wise to "monitor" the events and send them over to the primary form. You can also "eat" messages going to the mirror form that would cause focus to change (e.g. there may be an issue if input focus suddenly shifts from the primary form to the mirror form while the user thinks they're interacting with the primary form).
For more info on Messages look into overriding then WndProc of the Form (which is really Control.WndProc) and here. A nice overview article is Deliver The Power Of Spy++ To Windows Forms With Our New Tool. It also deals with cross-process communication which isn't relevant but explains a lot of the detail on messages and intercepting them.

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

Prevent other windows from overlapping my form?

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.

Duplicate a window in all screens

In a multi-monitor environment, how can I display a form on all the screens? Is it possible to get handles to the different screens available, and display a form in a different screen than where the main window lives?
What I really need to do is to clone a window on all displays.
A multi-monitor system effectively has a single, very large display area.
There is nothing different about a point in a different monitor; it will just be far to the right of the previous monitor.
You can use the Screen class to find all of the user's screens.
You can loop through Screen.AllScreens and create a new instance of the form for each screen, setting it's location to a point within that screen's WorkingArea.

Categories