Back to Devexpress

BarButtonItem.DropDownControl Property

windowsforms-devexpress-dot-xtrabars-dot-barbuttonitem.md

latest9.2 KB
Original Source

BarButtonItem.DropDownControl Property

Gets or sets a Dropdown control for the BarButtonItem component.

Namespace : DevExpress.XtraBars

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(null)]
public virtual PopupControl DropDownControl { get; set; }
vb
<DefaultValue(Nothing)>
Public Overridable Property DropDownControl As PopupControl

Property Value

TypeDefaultDescription
DevExpress.XtraBars.PopupControlnull

A Dropdown control for the BarButtonItem component.

|

Remarks

BarButtonItem objects may have a dropdown. A dropdown contains a specific control or a menu, which appears when users click the button (or its dropdown arrow). To enable the dropdown, set the BarButtonItem.ButtonStyle property to BarButtonStyle.DropDown, and assign a dropdown control to the DropDownControl property.

The DropDownControl property accepts the following objects:

The code sample below illustrates how to implement a bar button with zoom options in a dropdown.

csharp
using DevExpress.XtraEditors;
using DevExpress.XtraBars;

namespace WindowsFormsApp1
{
  public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
    {
    public XtraForm3()
        {
        InitializeComponent();

        BarManager barManager = new BarManager();
            barManager.Form = this;

            barManager.BeginUpdate();
            Bar bar1 = new Bar(barManager, "My Bar");
            bar1.DockStyle = BarDockStyle.Top;
            BarButtonItem buttonViewOutput = new BarButtonItem(barManager, "Zoom");
            bar1.AddItem(buttonViewOutput);
            barManager.EndUpdate();

            buttonViewOutput.ButtonStyle = BarButtonStyle.DropDown;
            buttonViewOutput.DropDownEnabled = true;

            Label scaleLabel = new Label();
            scaleLabel.Text = "Zoom to:";
            scaleLabel.Dock = DockStyle.Top;

            SpinEdit scaleSpin = new SpinEdit();
            scaleSpin.Dock = DockStyle.Bottom;
            scaleSpin.EditValue = 135;

            Label scaleSpinLabel = new Label();
            scaleSpinLabel.Width = 50;
            scaleSpinLabel.Padding = new Padding(0,10,0,0);
            scaleSpinLabel.Text = "Percent:";
            scaleSpinLabel.Dock = DockStyle.Left;

            RadioGroup scaleRadio = new RadioGroup();
            scaleRadio.Properties.Columns = 2;
            scaleRadio.Dock = DockStyle.Top;
            scaleRadio.Properties.Items.Add(new RadioGroupItem { Description="200%" });
            scaleRadio.Properties.Items.Add(new RadioGroupItem { Description = "100%" });
            scaleRadio.Properties.Items.Add(new RadioGroupItem { Description = "75%" });
            scaleRadio.Properties.Items.Add(new RadioGroupItem { Description = "Page width" });
            scaleRadio.Properties.Items.Add(new RadioGroupItem { Description = "Whole width" });

            PopupControlContainer container = new PopupControlContainer();
            container.Padding = new Padding(10);
            container.Height = 165;
            container.Width = 200;
            container.Manager = barManager1;
            container.Controls.Add(scaleSpin);
            container.Controls.Add(scaleSpinLabel);
            container.Controls.Add(scaleRadio);
            container.Controls.Add(scaleLabel);
            buttonViewOutput.DropDownControl = container;
        }
    }
}
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraBars

Namespace WindowsFormsApp1
  Partial Public Class XtraForm1
      Inherits DevExpress.XtraEditors.XtraForm

    Private Function XtraForm3() As Public
        InitializeComponent()

        Dim barManager As New BarManager()
            barManager.Form = Me

            barManager.BeginUpdate()
            Dim bar1 As New Bar(barManager, "My Bar")
            bar1.DockStyle = BarDockStyle.Top
            Dim buttonViewOutput As New BarButtonItem(barManager, "Zoom")
            bar1.AddItem(buttonViewOutput)
            barManager.EndUpdate()

            buttonViewOutput.ButtonStyle = BarButtonStyle.DropDown
            buttonViewOutput.DropDownEnabled = True

            Dim scaleLabel As New Label()
            scaleLabel.Text = "Zoom to:"
            scaleLabel.Dock = DockStyle.Top

            Dim scaleSpin As New SpinEdit()
            scaleSpin.Dock = DockStyle.Bottom
            scaleSpin.EditValue = 135

            Dim scaleSpinLabel As New Label()
            scaleSpinLabel.Width = 50
            scaleSpinLabel.Padding = New Padding(0,10,0,0)
            scaleSpinLabel.Text = "Percent:"
            scaleSpinLabel.Dock = DockStyle.Left

            Dim scaleRadio As New RadioGroup()
            scaleRadio.Properties.Columns = 2
            scaleRadio.Dock = DockStyle.Top
            scaleRadio.Properties.Items.Add(New RadioGroupItem With {.Description="200%"})
            scaleRadio.Properties.Items.Add(New RadioGroupItem With {.Description = "100%"})
            scaleRadio.Properties.Items.Add(New RadioGroupItem With {.Description = "75%"})
            scaleRadio.Properties.Items.Add(New RadioGroupItem With {.Description = "Page width"})
            scaleRadio.Properties.Items.Add(New RadioGroupItem With {.Description = "Whole width"})

            Dim container As New PopupControlContainer()
            container.Padding = New Padding(10)
            container.Height = 165
            container.Width = 200
            container.Manager = barManager1
            container.Controls.Add(scaleSpin)
            container.Controls.Add(scaleSpinLabel)
            container.Controls.Add(scaleRadio)
            container.Controls.Add(scaleLabel)
            buttonViewOutput.DropDownControl = container
    End Function
  End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DropDownControl property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-winforms-export-doc-odt/CS/WindowsFormsApplication1/Form1.cs#L37

csharp
PrintPreviewBarItem item = (PrintPreviewBarItem)form.PrintBarManager.GetBarItemByCommand(PrintingSystemCommand.ExportFile);
PopupMenu control = (PopupMenu)((DevExpress.XtraBars.BarButtonItem)(item)).DropDownControl;
BarButtonItem barItem = new BarButtonItem();

reporting-winforms-export-doc-odt/VB/WindowsFormsApplication1/Form1.vb#L37

vb
Dim item As PrintPreviewBarItem = CType(form.PrintBarManager.GetBarItemByCommand(PrintingSystemCommand.ExportFile), PrintPreviewBarItem)
Dim control As PopupMenu = CType((CType(item, DevExpress.XtraBars.BarButtonItem)).DropDownControl, PopupMenu)
Dim barItem As New BarButtonItem()

See Also

ActAsDropDown

ButtonStyle

DropDownEnabled

DropDownKeyTip

BarButtonItem Class

BarButtonItem Members

DevExpress.XtraBars Namespace