Results 1 to 7 of 7

Thread: Form size and position.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    9

    Form size and position.

    Hello everybody, can anybody tell me, what do I need to do to make my forms position and size remembered. Example: User opens a program on his PC, resize the form, and positions it anywhere he wants, closes the program, then reopens it, and the form opens in position where it was when it was closed, also with the same size when it was closed.

  2. #2
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: Form size and position.

    1. You need your program to create a file and write form size and screen coordinates to it.
    2. On your Form_Load event, you open that file, read form size and position data from it and adjust your form properties with new data.
    No, that wont do!

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    9

    Re: Form size and position.

    And, how do i do that, I am a beginner in Visual Basic after all. How would you do that? I suppose that it has something to do with Visual Basic Scripting... ???

  4. #4
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Form size and position.

    I use an ini file, but you can also use the registry. read about file handling in the code bank.
    Using the registary:
    http://www.planet-source-code.com/vb...29083&lngWId=1
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Form size and position.

    Here is a quick sample using the SaveSetting and GetSetting functions to save the values to the registry.
    Code:
    Private Sub Form_Load()
    Dim lngLeft As Long
    Dim lngTop As Long
    Dim lngWidth As Long
    Dim lngHeight As Long
    
        lngLeft = Val(GetSetting(App.EXEName, "Settings", "Left", "0"))
        lngTop = Val(GetSetting(App.EXEName, "Settings", "Top", "0"))
        lngWidth = Val(GetSetting(App.EXEName, "Settings", "Width", "0"))
        lngHeight = Val(GetSetting(App.EXEName, "Settings", "Height", "0"))
        
        If lngWidth > 0 Then
            Me.Move lngLeft, lngTop, lngWidth, lngHeight
        End If
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        SaveSetting App.EXEName, "Settings", "Left", Me.Left
        SaveSetting App.EXEName, "Settings", "Top", Me.Top
        SaveSetting App.EXEName, "Settings", "Width", Me.Width
        SaveSetting App.EXEName, "Settings", "Height", Me.Height
    End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    9

    Re: Form size and position.

    Thanks a lot, this is a complete solution for what i need!!!

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Form size and position.

    Now that we've helped you, you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that easily by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help.

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