Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remembering PopUp form size and position between uses

Status
Not open for further replies.

SBendBuckeye

Programmer
Joined
May 22, 2002
Messages
2,166
Location
US
Hello All,

I have a readonly non modal popup form that is displayed when the user clicks a command button. I want to remember the size and location when it is closed. I have the Size property working, but am not having a lot of success with getting the position right.

I guess I'm tired after 12 hrs. Can someone point me? It would be great if someone could also explain PointToScreen and PointToClient. Thanks in advance for any ideas and/or suggestions!

Have a great day!

j2consulting@yahoo.com
 
You can use one global variable: PopupXY (Public PopupXY as system.drawing.point). At the popup's form Closing event handler write:

PopupXY = Me.Location

At the Popup's form load event handler write:

me.location = PopupXY

This is a way. An other is to save it as a setting. On solution explorer click the icon 'show all files'. Expand 'my project' and dbclick the 'setting.setting'
 
Pressed submit by mistake...

This is a way. An other is to save it as a setting. On solution explorer click the icon 'show all files'. Expand 'my project' and dbclick the 'Settings.settings'. This way is ideal (hope this is the right word..) if you want to remember stuff even if you close and launch again your application.
If you have any problem with the settings.. i'm here.
 
I know I need a point object, but isn't location relative to the screen instead of the form? If I want to center my PopUp on the main form, how do I convert the coordinates?

Have a great day!

j2consulting@yahoo.com
 
Forms have a StartPosition property that can be set to CenterParent.

I'm not familiar with Settings.Settings, is this a 2k5 feature?

For storing values like this I usually use a dataset's ReadXML and WriteXML to store key-value pairs in an XML file in the user's Application Settings folder.

-rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Yes this is a 2005 feature.
Anyway. To center a form: there is a property of the form to center it at screen or at parent. But you can do it manually using 'screen.' :

-> Screen.PrimaryScreen.Bounds.Width and .height, and a little math operations (form's size is known: me.size.width and .height).

^ As for the storing, use as you like. Use settings (MY namespace, use txt file, use Rick's suggestion etc)

Hope this helps
 
Hello TG,

I already tried saving the form's location point when it exited, but that does not position it at the same place the next time the user pops the PopUp form. Thanks!

Hello TGR,

Is the parent the screen or the calling form? In either event, that didn't seem to work very well either. This is not a show stopper, but it is irritating for sure.

Thanks to both of you for your interest and responses.


Have a great day!

j2consulting@yahoo.com
 
How do you store the location? Perhaps i can give you an example (code)
 
I found it, saving the location works. I forgot to set the popup form's StartPosition property to Manual.

To answer your question, I don't persist the values, at least not now. I just keep them for the current session.

What makes it kind of interesting is that I have multiple combo boxes on the main Windows form which all share the same non modal popup form. So I have a private nested class which holds an IsOpen property along with size and location properties.

I store helper class instances in a hashtable keyed on the active combobox behind the request. That way I can check the IsOpen property and only allow 1 popup per combobox. This piece has been interesting except for the several hours I spent beating my head on this thread, no fault of yours of course. Thanks again for your help and interest!

Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top