can i right align a toolbar?

J

jimi_hendricks

Hi folks,

I have a custom toolbar which has to move position when one of the buttons
is clicked.

I want the toolbar to shift over to the right of the screen, then revert to
the left when the button is clicked again...

Is there someting as straightforward as an 'alignment' property? the best i
could find was position, which i set to msoBarTop, but that doesn't specify a
position on the top toolbar area.

can i set the value of '.Left' to the width of the screen minus the width of
the toolbar?

thanks in advance.
jimi
 
H

Helmut Weber

Hi Jimi,

something like that:

With Application.CommandBars("Standard")
..Top = 0 ' try some other value to see what it does
If .Position = msoBarLeft Then
.Position = msoBarRight
Else
.Position = msoBarLeft
End If
End With
End Sub

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
J

jimi_hendricks

Hi Helmut,

Thanks for the suggestion. I really need the toolbar to be anchored to the
top row though, just aligned to the right, (as opposed to being anchored to
the right, like with msoBarRight).

if i could grab the screenwidth i could set the .left value to
screenwidth-toolbarwidth.

do you happen to know if that's possible?

thanks for your time.

kind regards,
jimi
 
H

Helmut Weber

Hi Jimi,

I see, hm...

strange enough, this here seems to work,
tested though with a maximized window,
Might work with custom size, too.
But you never know, no time to test it.


Sub moveme()
Dim x1 As Long
Dim x2 As Long
With Application.CommandBars("Standard")
x1 = .Width
x2 = Application.ActiveWindow.Width
.Left = x2 * 2 - x1 ' factor 2
' moveback
.Left = 0
End With
End Sub

Use single mode to check, of course.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
J

jimi_hendricks

Hi Helmut,

Your post helped me, thanks.

I've moved it forward a step now though, and using the same code is causing
me a problem...

i have now made the toolbar position msoBarFloating, and what i'm trying to
achieve is:

(this is all happening when in full screen mode)

in the normal state, for the toolbar to have one button and be aligned at
the right edge as a floating toolbar. Then when the button is pressed the
toolbar should 'expand' (shift to the left) to allow space to show more
functions.

However, the toolbar is way too far over to the right and as a result most
of the new buttons are off the screen.

the code i use is:

'if command = show buttons
'code for making all extra buttons enabled and visible
'else if command = hide buttons
'code for making all extra buttons disabled and invisible
'end if

Dim x1 As Long
Dim x2 As Long
Dim x3 As Long

With CommandBars("CustomToolbar")
x1 = .Width
x2 = Application.Width
.Left = (x2 * 2) - x1
End With

since all the buttons are enabled/disabled beforehand, the width property of
the toolbar should be accurate when i use it to set the left property.
indeed, when i step through, the values all seem correct, but it still places
the toolbar too far to the right!

any thoughts as to why this is happening?

thanks!
jimi

p.s. (i was curious as to why application.width or
application.activewindow.width return only half the true width of the screen
so that the value must therefore be doubled?)
 
H

Helmut Weber

Hi Jimi,

so far this was more guessing than knowing from my side.
However, it sometimes help.
Seems, working with activewindow.width leeds to nothing.

But, I managed to position a toolbar containing 6 standard
icons with it's right edge at the rightmost pixel
on an 1024 pixels wide screen. The width of the toolbar
is at a 1024 pixel screen = 144. Makes 24 pixel
for each icon. The left of a 6 icon toolbar is then at 880.
Astonishingly simple, once you know, isn't it?
So if you want to display 10 icons, left would be 1024 - 10*24.
So if you want to display 1 icon, left would be 1024 - 24,
plus some offset for the x in right hand top corner of the toolbar
plus for the down arrow indicated left ot it, if you want to show it.
But that's the fun bit.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
J

jimi_hendricks

Dear Helmut

Thanks for your additional help. You're right it's simple once you know how!

I really need to implement a solution that works with different screen
resolutions, so i'll keep hunting for a way to get this.

It seems strange that Application.Width and ActiveWindow.Width don't give
this reliably.

Thanks again,
jimi
 
J

jimi_hendricks

Hi Helmut,

I found that System.HorizontalResolution did the trick.

Thanks for your ongoing help.

Regards,
Jimi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top