Home Forums WinForms controls Other WinForms controls ToolBar Button Alignment Reply To: ToolBar Button Alignment

User (Old forums)
Post count: 23064

Putting a SpringPanel in the toolbar will not spring the button after it to the far right. You may want to send this to technical support so this issue can be fixed in a later release.

I did however find a temporary fix you can use, though you may need to tinker with it a bit to fit it to your liking.

In order to make this work, you will need to add a blank (no text & zero width) LabelTool on the toolbar in front of the button you want to push to the far right. The Tool button also needs to be assigned a default width big enough to hold its text string. In my case, I assigned a TextWidth of 50 to the button. Then in your Form SizeChanged event, put some code like the following:

Private Sub frmMain_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
Dim width As Integer
width = Me.Width – RightToolButton.TextWidth – tbStore.Bounds.Right – 20
If width > 0 Then
LabelTool2.Width = width
End If
End Sub

Basically, what the code I just posted does is this:

1) Create a temporary variable to hold the width for the LabelTool.
2) Get your form’s width, then subtract the width of the RightToolButton from it. Then get the right position of the SmartItem that is before the LabelTool on the toolbar and subtract that. In my case, I had a button called ‘tbStore’ in front of the label. Lastly, you need to subtract around 20 or so more pixels from the width to fit the RightToolButton on the same line. This value may be able to be shortened, based on what SmartItem you are trying to put on the far right.
3) Finally, you make sure the width value is greater than 0 before you assign it to the LabelTool. If it is greater than 0, then you are making the LabelTool visible and assigning it a new width. If it is not greater than 0, then you are hiding the LabelTool, as you won’t need it to push the button.

If you can think of a better solution let me know, as this is all I could think of. 😉

Imported from legacy forums. Posted by paulplatter (had 6059 views)