Skip to content

Commit 333f529

Browse files
authored
Merge pull request #805 from telerik/new-kb-ribbonbar-adding-right-aligned-elements-across-ribbontabs-0d765d2863e94871b01e8596bb2a61b4
Added new kb article ribbonbar-adding-right-aligned-elements-across-ribbontabs
2 parents 3641b27 + 27d2ae9 commit 333f529

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: Adding a Right-Aligned Button Visible Across All RibbonTabs in RadRibbonBar
3+
description: Learn how to add a button or control that remains visible and right-aligned across all RibbonTabs in RadRibbonBar, even when the window is resized.
4+
type: how-to
5+
page_title: How to Add a Right-Aligned Button Across RibbonTabs in RadRibbonBar
6+
meta_title: How to Add a Right-Aligned Button Across RibbonTabs in RadRibbonBar
7+
slug: ribbonbar-adding-right-aligned-elements-across-ribbontabs
8+
tags: ribbonbar, ui for winforms, button, control, alignment, radribbonbar
9+
res_type: kb
10+
ticketid: 1700786
11+
---
12+
13+
## Environment
14+
15+
|Product Version|Product|Author|
16+
|----|----|----|
17+
|2025.3.812|RadRibbonBar for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)|
18+
19+
## Description
20+
21+
In this tutorial, we will demonstrate how to add a button or any control that remains visible and right-aligned in the RadRibbonBar across all RibbonTabs. The control should stay in the right corner even when the window is resized.
22+
23+
## Solution
24+
25+
In general, the RadRibbonBar control uses the RadPageView control internally. The RadPageView control exposes StripButtons (Scrolling and Overflow (strip buttons) ). We can use the panel in which these buttons are placed. The panel can be shown when one of the buttons is visible. Then you can hide only the buttons and leave the panel visible. Then, we can position our elements inside that panel on the right. In the following example, we will add a label and a button in the Load event of the Form:
26+
27+
Here is the code example:
28+
29+
````C#
30+
protected override void OnLoad(EventArgs e)
31+
{
32+
RadPageViewStripElement strip = this.radRibbonBar1.RibbonBarElement.TabStripElement as RadPageViewStripElement;
33+
34+
// Set StripButtons to Close
35+
strip.StripButtons = StripViewButtons.Close;
36+
37+
// Hide strip buttons
38+
foreach (var c in strip.ItemContainer.ButtonsPanel.Children)
39+
{
40+
RadPageViewStripButtonElement b = c as RadPageViewStripButtonElement;
41+
if (b != null)
42+
{
43+
b.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
44+
}
45+
}
46+
47+
// Hide the ItemListButton
48+
strip.ItemContainer.ButtonsPanel.ItemListButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
49+
50+
// Create custom layout with label and button
51+
StackLayoutElement stack = new StackLayoutElement();
52+
stack.StretchHorizontally = true;
53+
54+
LightVisualElement text = new LightVisualElement();
55+
text.StretchHorizontally = true;
56+
text.TextAlignment = ContentAlignment.MiddleRight;
57+
text.Text = "Button: ";
58+
59+
RadButtonElement btn = new RadButtonElement();
60+
btn.StretchHorizontally = false;
61+
btn.Alignment = ContentAlignment.MiddleRight;
62+
btn.Text = "Delete";
63+
btn.MaxSize = new System.Drawing.Size(60, 20);
64+
btn.Click += btn_Click;
65+
66+
stack.Children.Add(text);
67+
stack.Children.Add(btn);
68+
stack.MinSize = new System.Drawing.Size(350, 0);
69+
70+
// Insert the custom layout into ButtonsPanel
71+
strip.ItemContainer.ButtonsPanel.Children.Insert(0, stack);
72+
}
73+
74+
````
75+
76+
Replace the label and button with your desired controls. Ensure proper alignment for each element added.
77+
78+
## See Also
79+
80+
* [RadPageView](https://docs.telerik.com/devtools/winforms/controls/pageview/overview)
81+
* [RadRibbonBar Documentation](https://docs.telerik.com/devtools/winforms/controls/ribbonbar/overview)
82+
* [Scrolling and Overflow (strip buttons)](https://docs.telerik.com/devtools/winforms/controls/pageview/stripview/scrolling-and-overflow-(strip-buttons))

0 commit comments

Comments
 (0)