windowsforms-devexpress-dot-xtrabars-dot-ribbon-dot-ribboncontrol-f1def7f5.md
Allows you to align the Search box within the header of the Ribbon form.
Namespace : DevExpress.XtraBars.Ribbon
Assembly : DevExpress.XtraBars.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event RibbonCustomSearchItemPositionHandler CustomSearchItemPosition
<DXCategory("Events")>
Public Event CustomSearchItemPosition As RibbonCustomSearchItemPositionHandler
The CustomSearchItemPosition event's data class is DevExpress.XtraBars.Ribbon.RibbonCustomSearchItemPositionArgs.
The Ribbon control raises the CustomSearchItemPosition event when the Search box is displayed at the top of the Ribbon form (SearchItemPosition is set to SearchItemPosition.Caption). Handle this event to align the Search box within the header of the Ribbon form.
The e.SearchItemBounds property specifies the size and position of the Search box.
Use the e.Bounds property to obtain the area within the header of the form where the Search box can be displayed.
The e.IsCollapsed property allows you to identify whether the Search box is collapsed when the width of the form is too small.
Use the e.IsActive property to obtain whether the Search box is focused.
The following example demonstrates how to align the Search box to the right of the form caption:
using System.Drawing;
using DevExpress.XtraBars.Ribbon;
namespace DXApplication11 {
public partial class Form1 : RibbonForm {
public Form1() {
InitializeComponent();
ribbonControl1.OptionsSearchMenu.SearchItemPosition = SearchItemPosition.Caption;
ribbonControl1.RibbonCaptionAlignment = RibbonCaptionAlignment.Center;
ribbonControl1.CustomSearchItemPosition += RibbonControl1_CustomSearchItemPosition;
}
private void RibbonControl1_CustomSearchItemPosition(object sender, RibbonCustomSearchItemPositionArgs e) {
if(e.IsCollapsed) return;
int searchItemWidth = e.SearchItemBounds.Width <= 360 ? e.SearchItemBounds.Width : 360;
e.SearchItemBounds = new Rectangle(
e.Bounds.Width - searchItemWidth,
e.SearchItemBounds.Y,
searchItemWidth,
e.SearchItemBounds.Height);
}
}
}
Imports System.Drawing
Imports DevExpress.XtraBars.Ribbon
Namespace DXApplication11
Partial Public Class Form1
Inherits RibbonForm
Public Sub New()
InitializeComponent()
ribbonControl1.OptionsSearchMenu.SearchItemPosition = SearchItemPosition.Caption
ribbonControl1.RibbonCaptionAlignment = RibbonCaptionAlignment.Center
AddHandler ribbonControl1.CustomSearchItemPosition, AddressOf RibbonControl1_CustomSearchItemPosition
End Sub
Private Sub RibbonControl1_CustomSearchItemPosition(ByVal sender As Object, ByVal e As RibbonCustomSearchItemPositionArgs)
If e.IsCollapsed Then
Return
End If
Dim searchItemWidth As Integer = If(e.SearchItemBounds.Width <= 360, e.SearchItemBounds.Width, 360)
e.SearchItemBounds = New Rectangle(e.Bounds.Width - searchItemWidth, e.SearchItemBounds.Y, searchItemWidth, e.SearchItemBounds.Height)
End Sub
End Class
End Namespace
See Also