|
-
Nov 6th, 2003, 08:27 PM
#1
Thread Starter
Addicted Member
Window Position (RESOLVED)
Anyone know how to save and restore window positions in .NET?
Last edited by GSIV; Nov 6th, 2003 at 09:52 PM.
-
Nov 6th, 2003, 09:14 PM
#2
Just store and restore the Location property of the form. Here is an example although there are plenty of different ways of storing the info. I would probably store the location in the app.config file if I was going to actually do this, but serialization was an easier example.
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If IO.File.Exists("form.config") Then
Dim xs As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim fs As New IO.FileStream("form.config", IO.FileMode.OpenOrCreate)
Dim pt As Point = xs.Deserialize(fs)
fs.Close()
Me.Location = pt
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim xs As New Xml.Serialization.XmlSerializer(GetType(Point))
Dim fs As New IO.FileStream("form.config", IO.FileMode.OpenOrCreate)
xs.Serialize(fs, Me.Location)
fs.Close()
End Sub
-
Nov 6th, 2003, 09:50 PM
#3
Thread Starter
Addicted Member
Thanks again... you keep kick starting me (haha). This is the concept that I was looking for. I had been storing the info in the registry using VB6, but I'm having trouble converting my code. Then I found this:
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'Set window state and position
WindowState = FormWindowState.Normal
StartPosition = FormStartPosition.CenterScreen
And this sets a starting position, but not based on the last used. Now I can get it a little closer.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|