RibbonControl.CustomSearchItemPosition Event
Allows you to align the Search box within the header of the Ribbon form.
Namespace: DevExpress.XtraBars.Ribbon
Assembly: DevExpress.XtraBars.v24.2.dll
Declaration
[DXCategory("Events")]
public event RibbonCustomSearchItemPositionHandler CustomSearchItemPosition
Event Data
The CustomSearchItemPosition event's data class is DevExpress.XtraBars.Ribbon.RibbonCustomSearchItemPositionArgs.
Remarks
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.
Example
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);
}
}
}