Make the UserForm full screen and center the controls.

ajca29 Posted messages 9 Status Member -  
ajca29 Posted messages 9 Status Member -
Hello,

I have a sports results management program and my issue is as follows:
- I can display the userform in full screen but the controls are correctly represented, only on the left side of the userform (with only the initialize part).
- The attached code, activate, only shows a small portion of the userform at the top left of the screen.

Could you suggest a solution for me?

Thank you for your help
Best regards
ajca29

Private Sub Workbook_Open()
'Hide the columns containing warnings
Columns("CB:DA").Select
Selection.EntireColumn.Hidden = True
UserForm2.Show
End Sub

Private Sub UserForm_Initialize()
With UserForm2
.StartUpPosition = 3
.Width = Application.Width
.Height = Application.Height
End With
End Sub

Private Sub UserForm_Activate()
Dim RW As Single, RH As Single
Me.Width = ScreenWidth * PointsPerPixel
Me.Height = ScreenHeight * PointsPerPixel
RW = ScreenWidth * PointsPerPixel / Me.Width
RH = ScreenHeight * PointsPerPixel / Me.Height
Dim Ctl As MSForms.Control
For Each Ctl In Me.Controls
Ctl.Move Ctl.Left * RW, Ctl.Top * RH, Ctl.Width * RW, Ctl.Height * RH
Next
End Sub


Private Sub Bouton_Annulation_Click()
TextBox1.Text = "" 'Clear the contents of the TextBox
TextBox2.Text = ""
TextBox3.Text = ""
End Sub

Configuration: Windows 8 / Internet Explorer 10.0

3 answers

  1. Zoul67 Posted messages 2001 Status Member 149
     
    Hello,

    Your question is very similar to the topic discussed here: https://forums.commentcamarche.net/forum/affich-4340944-vba-taille-userform-sous-excel#3
    The variables in bold in your code are only calculated if you define the associated functions (ScreenWidth,...).

    See you.
    0
    1. ajca29 Posted messages 9 Status Member
       
      Thank you Zoul67,
      But I've tried all the codes and even added the module recommended by Didier09, but nothing works.
      I have the user form in full screen and all the controls are correctly placed on the left side of the form. That's what I'm missing.
      Best regards
      ajca29
      0
    2. Zoul67 Posted messages 2001 Status Member 149
       
      Is your file confidential or can you make it available to us (on cjoint.com for example)?
      0
    3. ajca29 Posted messages 9 Status Member
       
      Of course, it is uploaded on cjoint.com.
      Thanks again
      ajca29
      0
    4. Zoul67 Posted messages 2001 Status Member 149
       
      Thank you for providing the link corresponding to your file. You only mentioned cjoint.com ...
      0
    5. ajca29 Posted messages 9 Status Member
       
      https://www.cjoint.com/?0Iehv6wdEhj
      When I go to cjoint, it tells me that the link is not available or no longer available.
      This is a new link.
      0
  2. lermite222 Posted messages 9042 Status Contributor 1 199
     
    Hello,
    What version of Excel please?
    If it's 2007 or later, check out this tutorial.

    See you!

    --
    If you bump into a pot and it sounds hollow, it's not necessarily the pot that's empty. ;-)(Confucius)
    Note: I do not respond to private messages for technical questions. And my crystal ball is broken.
    0
    1. ajca29 Posted messages 9 Status Member
       
      Thank you for the tutorial, it’s indeed Excel 2007.
      Best regards
      ajca29
      0