473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How can I have my program start in the last position I placed it?

110 100+
I have a program that when I first run opens in the upper left hand corner of the screen. I will move it somewhere else on the screen, then close it. When I open it again it opens in the upper left hand corner again. I have the forms startposition set to Manual but that doesn't seem to be the solution. Can anyone offer any ideas on how to make it launch in the last place I had put it before closing the program?
Aug 3 '11 #1

✓ answered by GaryTexmo

Setting the start position just means it will appear in the position you tell it to (via the Location property). In order to do this, when your program closes you need to save the Location to a file of some kind, then when your program starts up again, read that file and set the Location accordingly.

How you save it is up to you, but you can look into using the Settings class or you can just write it to a file yourself.

There is a few gotchas that you should be aware of though. The most important one is that when Windows minimizes your program, it actually sets the Location to something like -32000, -32000. When you go to write your program you'll need to check to see if it's minimized and possibly restore it before you get the Location. Another thing to be aware of is having a system with multiple screens, then loading your program up with the same config in another screen configuration (physical dual screen and remote desktop single screen is a great example). The windows desktop is a big canvas where you only see what your screens show, so if your app starts up and sets a form position to a location that's off your desktop, you just won't see the form. The best idea is to get the area of your screens using the Screen class and make sure your form will be visible on it. If not, start it up in the default position.

I hope that helps :)

2 1818
GaryTexmo
1,501 Expert 1GB
Setting the start position just means it will appear in the position you tell it to (via the Location property). In order to do this, when your program closes you need to save the Location to a file of some kind, then when your program starts up again, read that file and set the Location accordingly.

How you save it is up to you, but you can look into using the Settings class or you can just write it to a file yourself.

There is a few gotchas that you should be aware of though. The most important one is that when Windows minimizes your program, it actually sets the Location to something like -32000, -32000. When you go to write your program you'll need to check to see if it's minimized and possibly restore it before you get the Location. Another thing to be aware of is having a system with multiple screens, then loading your program up with the same config in another screen configuration (physical dual screen and remote desktop single screen is a great example). The windows desktop is a big canvas where you only see what your screens show, so if your app starts up and sets a form position to a location that's off your desktop, you just won't see the form. The best idea is to get the area of your screens using the Screen class and make sure your form will be visible on it. If not, start it up in the default position.

I hope that helps :)
Aug 4 '11 #2
Fuzz13
110 100+
Gary that is awesome. I thought writing the location to the settings might be the only option but I wanted to check anyhow. I really appreciate those little "gotcha" notes you gave, it would have been extremely frustrating coming up against it later on. Thanks again!
Aug 5 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: b0yce | last post by:
Hi all, I am trying to create a recursive loop transformation that remembers last position of inner loop so that it continues from that point instead of the point from where the recursion...
3
by: jason | last post by:
I've got this javascript routine (i found on google - thank you) in an asp.net page that on page reload sets the cursor of a textbox to the last line. It works great! Using a similar concept, I...
16
by: Konrad Viltersten | last post by:
Suppose you got a really long page and you'd like to enable the user (supposedly, there's only one but if it's not to difficult we could extend that to any number) not to have to scroll to the...
3
by: Harry | last post by:
Where can i find sample programme Please!
8
by: koorb | last post by:
I am starting a program from a module with the Sub main procedure and I want it to display two forms for the program's interface, but when I run the program both forms just open and then program...
2
by: Paul Ilacqua | last post by:
All, I'm using VB Express 2005 and for the life of me I cannot locate the "Last Position" right mouse button choice or menu item for when you are navigating through a large module or class. If I...
3
by: Mark | last post by:
Probably a really obvious question but... In vb6 when writing code, there was a last position option in the context menu to allow you to jump back to the last proceedure youi were editing. Is...
4
by: WayneM | last post by:
In VB6 there was a Last Position in the popup menu that took you back in the IDE to the last line that you were working on. Is there an equivalent in VS2005? Thanks for info in advanced, ...
4
by: SoulSeeker | last post by:
Hello. How I can start my M$ access form with last edited record? What I must put in "on load" field? Tnx. for advice.
1
by: =?Utf-8?B?SkQ=?= | last post by:
ok, I got a windows xp home edition computer from my friend, it is a custom made one. The windows xp is an OEM product, so microsoft is willing to charge me $59 to tell me how to fix it since its...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.