I'm testing some 3rd-party software and I noticed that the application
doesn't remember which monitor it was last running on and always opens on my
primary monitor. This got me thinking that if I were ever to write an app
for widespread distribution, I'd want to go the extra mile and add this
funcrtionality to it to give it that extra professional touch. So how do I
do it? What class, if any, would give me this kind of information? Do I have
to use P/Invoke?
ThunderMusic - 15 Jun 2007 20:19 GMT
I haven't tested it because I only have one monitor, but when your app
closes, just remember the last position it was on (Top, Left,
WindowState)... And when it starts again, put this position right back and
voilà!!
I used this since VB 3 and it always worked, so I don't see why it wouldn't
work anymore... ;)
good luck
ThunderMusic
> I'm testing some 3rd-party software and I noticed that the application
> doesn't remember which monitor it was last running on and always opens on
[quoted text clipped - 3 lines]
> do I do it? What class, if any, would give me this kind of information? Do
> I have to use P/Invoke?
Wolfgang Hauer - 15 Jun 2007 21:05 GMT
Hi!
If you remember position, don't forget to check, if the saved position is
now valid. For example if you remove a monitor, or work with
terminalservice.
Wolfgang
>I haven't tested it because I only have one monitor, but when your app
>closes, just remember the last position it was on (Top, Left,
[quoted text clipped - 15 lines]
>> how do I do it? What class, if any, would give me this kind of
>> information? Do I have to use P/Invoke?
Frans Bouma [C# MVP] - 16 Jun 2007 10:06 GMT
> I'm testing some 3rd-party software and I noticed that the
> application doesn't remember which monitor it was last running on and
[quoted text clipped - 3 lines]
> extra professional touch. So how do I do it? What class, if any,
> would give me this kind of information? Do I have to use P/Invoke?
Normally, windows will remember, and if you use for example ultramon,
it works OK. My .NET application doesn't have any logic build in for
its main app location with multimonitor setups, but it starts up on the
monitor I closed it on, because windows takes care of that.
That's not true for child windows though. So if you have your main app
on monitor 2, and you open a dialog which is moved to monitor 1 by the
user, and you close the app, the dialog will be placed at monitor 2,
very likely (unless you choose the useless setting of letting windows
handle where the dialog pops up which is always not the location you
want it to be).
In that case, check out the DesktopBounds property of a form. :) Set
the saved DesktopBounds struct of a previous location it in the Load
event handler of the form and everything is good.
FB

Signature
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------