[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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?
0
traderSPT
Asked:
traderSPT
1 Solution
 
setiawanCommented:
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
0
 
deightonCommented:
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
0
 
caraf_gCommented:
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
caraf_gCommented:
hehe. pipped at the post ;-)
0
 
deightonCommented:
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
0
 
amebaCommented:
>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
0
 
traderSPTAuthor Commented:
Many Thanks for the help I had the scalewidth height etc sorted but couldnt get it to update the form once it was running.

0
 
deightonCommented:
You should perhaps have awarded ameba the question, since his info was what you needed.  
0
 
trick_jcCommented:
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
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now