Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

vba - Aligning controls in a multipage

i have a userform with x2 multipages of same dimensions. each has a commandbutton. The first multipage has tabs orientation set to left and the other set to top. What i want to achive is to align the commandbuttons to bottom right of each of the multipaged.

Private Sub UserForm_Initialize()
    'align buttons to bottom right

    CommandButton1.Left = MultiPage1.Width - CommandButton1.Width
    CommandButton1.Top = MultiPage1.Height - CommandButton1.Height

    CommandButton2.Left = MultiPage2.Width - CommandButton2.Width
    CommandButton2.Top = MultiPage2.Height - CommandButton2.Height
End Sub
question from:https://stackoverflow.com/questions/65926687/aligning-controls-in-a-multipage

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You will want to include a small buffer value as the tabs themselves have a height/width value too...

' tabs on the top
CommandButton1.Left = MultiPage1.Width - CommandButton1.Width - 5
CommandButton1.Top = MultiPage1.Height - CommandButton1.Height - 20

' tabs on the left
CommandButton1.Left = MultiPage1.Width - CommandButton1.Width - 48
CommandButton1.Top = MultiPage1.Height - CommandButton1.Height - 5

Adjust the numbers to give it the effect you want.

When the tabs are on the left, the width value is going to depend on how wide the tabs need to be in order for the text on them to fit. The values I used are for when the default tab text "Page1" and "Page2" are used.

If you decide to set the values of TabFixedWidth or TabFixedHeight (they default to 0), then you will want to use them in the calculation as well, or just use a larger adjustment value.

Note: the values will need to be adjusted if you change the size of the font for the tabs too, so you cannot just automatically assume that the values I gave you are going to work in your case.


Now think to yourself, is the size of the MultiPage really going to change at runtime? If so, you are going to have to write a lot of of code for each control on each page too, which you will eventually realize is going to be more effort than it is worth. Usually when people design something like this, all controls on each page are going to be in a static position, so none of this is needed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...