Link to home
Start Free TrialLog in
Avatar of traderSPT
traderSPT

asked on

Centred text on form

I am trying to develop a form that displays text.  However due to the nature of the form many situation will need to resize the form depending .

I want to keep the text in the centre of the form after the size of the form has been altered.

any ideas how to do this?
Avatar of setiawan
setiawan

Hi traderSPT,

What do you want to use ?
I assume you use labet to display text.

lbl1.left = (Form1.Width - Len(lbl1.text)) div 2
lbl1.heigh = Form1.Heigh div 2

hope this helps

  danny
Call centre(Text1)



Private Sub centre(x As Object)

    x.Left = Form1.ScaleWidth / 2 - x.Width / 2
    x.Top = Form1.ScaleHeight / 2 - x.Height / 2


End Sub
Yes, more or less correct. Except I would use ScaleWidth rather than Width for the form. And ScaleHeight. Make sure your form's ScaleMode remains as default: Twips.
hehe. pipped at the post ;-)
ASKER CERTIFIED SOLUTION
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>in the centre of the form after the size of the form has been altered.

One solution can be to put deighton's code in the Resize event of the form.

Private Sub Form_Resize()
    Call centre(Text1)
End Sub
Avatar of traderSPT

ASKER

Many Thanks for the help I had the scalewidth height etc sorted but couldnt get it to update the form once it was running.

You should perhaps have awarded ameba the question, since his info was what you needed.  
Use the RESIZE event of the form and use a label for displaying your text.

Private Sub Form_Load()
    Call Form_Resize
End Sub

Private Sub Form_Resize()

Label1.Top = (Me.Height / 2) -   (Label1.Height / 2)
Label1.Left = (Me.Width - Label1.Width) / 2

End Sub