Results 1 to 3 of 3

Thread: Window Position (RESOLVED)

  1. #1

    Thread Starter
    Addicted Member GSIV's Avatar
    Join Date
    Jun 2002
    Location
    Texas, USA
    Posts
    213

    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.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         If IO.File.Exists("form.config") Then
    3.             Dim xs As New Xml.Serialization.XmlSerializer(GetType(Point))
    4.             Dim fs As New IO.FileStream("form.config", IO.FileMode.OpenOrCreate)
    5.             Dim pt As Point = xs.Deserialize(fs)
    6.             fs.Close()
    7.             Me.Location = pt
    8.         End If
    9.     End Sub
    10.  
    11.     Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    12.         Dim xs As New Xml.Serialization.XmlSerializer(GetType(Point))
    13.         Dim fs As New IO.FileStream("form.config", IO.FileMode.OpenOrCreate)
    14.         xs.Serialize(fs, Me.Location)
    15.         fs.Close()
    16.     End Sub

  3. #3

    Thread Starter
    Addicted Member GSIV's Avatar
    Join Date
    Jun 2002
    Location
    Texas, USA
    Posts
    213
    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
  •  



Click Here to Expand Forum to Full Width