OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Form position (http://forum.oberonplace.com/showthread.php?t=7536)

PAnderson 01-02-2011 10:44

Form position
 
Is there some specific code I can add to my macros that will make a form remember its position the next time it is used?

Related to that, is there a default position for a form that works best for most PC resolutions? Would centering it in the window be best? I would love your input on this.

I should add that I tried using some of the code from a macro that John (a.k.a. runflacruiser) helped me with awhile back. However, I can't seem to get it to work. I'm not sure which part of the code specifically relates to the form positioning...or where it goes once I figure out which parts to use!

Thanks in advance,
Patti

runflacruiser 01-02-2011 18:45

Hi.
Make sure you type a default value in the form properties area for left and top (for the form) or the move function will not work.

-John

runflacruiser 01-02-2011 18:52

Hi.
Here's some form code. Don't forget to adjust the properties for the form in the properties section as I noted above or this will not work.

You can enter anything in form properties section. Ie left: 55, top: 55

Create a form called frmPatti and in it a command button called cmdGo

Add this code in form code:

Code:


Option Explicit

Private Sub cmbGo_Click()
    sms 'run the sms sub which saves any settings you want at runtime,
        'which in this case is a command button click
   
    'other subs here....
End Sub


Private Sub sms() 'save my settings (sms)
    'form position save
    'make sure you name the form whatever you want, change: frmPatti
    Dim fLeft#, fTop#
    fLeft = frmPatti.Left: fTop = frmPatti.Top
    SaveSetting "patti_form_tut", "Preferences", "form_left", fLeft
    SaveSetting "patti_form_tut", "Preferences", "form_top", fTop
End Sub


Private Sub UserForm_Initialize() 'runs when form loads

'code placed here will run when form loads
    Dim regMoveLeft, regMoveTop
   
    'get saved form positions from registry.
    regMoveLeft = GetSetting("patti_form_tut", "Preferences", "form_left")
    regMoveTop = GetSetting("patti_form_tut", "Preferences", "form_top")
   
    'move form to correct position if reg entries are not empty strings
    If regMoveLeft = "" Or regMoveTop = "" Then
      Move 55, 55
    ElseIf regMoveLeft <> "" And regMoveTop <> "" Then
        Move regMoveLeft, regMoveTop
    End If

End Sub

-John

PAnderson 01-02-2011 23:05

Thank you so much, John! I think I can figure it out now. After seeing the code outside from my other macro, things are making a little more sense now.

Patti


All times are GMT -5. The time now is 21:43.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com