본문 바로가기
C#/DevExpress

DevExpress / Winform Bar 생성하기.

by HyunS_ 2019. 5. 24.

Bar 생성하기 입니다.

 

Bar 생성하기 예제

MainForm.cs 입니다.

using System.Windows.Forms;

using DevExpress.XtraBars;

namespace WindowsFormsApp2
{
    /// <summary>
    /// 메인폼 클래스 입니다.
    /// </summary>
    public partial class MainForm : Form
    {
        // Constructor (Public)

        #region MainForm() - 메인폼 생성자 입니다.

        /// <summary>
        /// 메인폼 생성자 입니다.
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            #region Bar를 생성합니다.

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

            barManager.BeginUpdate();

            Bar bar1 = new Bar(barManager, "My MainMenu");
            Bar bar2 = new Bar(barManager, "My Bar");

            bar1.DockStyle = BarDockStyle.Top;
            bar2.DockStyle = BarDockStyle.Top;

            bar1.DockRow = 0;

            barManager.MainMenu = bar1;

            BarSubItem subMenuFile = new BarSubItem(barManager, "File");
            BarSubItem subMenuEdit = new BarSubItem(barManager, "Edit");
            BarSubItem subMenuView = new BarSubItem(barManager, "View");

            BarButtonItem buttonOpen       = new BarButtonItem(barManager, "Open"  );
            BarButtonItem buttonExit       = new BarButtonItem(barManager, "Exit"  );
            BarButtonItem buttonCopy       = new BarButtonItem(barManager, "Copy"  );
            BarButtonItem buttonCut        = new BarButtonItem(barManager, "Cut"   );
            BarButtonItem buttonViewOutput = new BarButtonItem(barManager, "Output");

            subMenuFile.AddItems(new BarItem[] { buttonOpen, buttonExit });
            subMenuFile.AddItems(new BarItem[] { buttonCopy, buttonCut  });
            subMenuView.AddItem (buttonViewOutput);

            bar1.AddItems(new BarItem[] { subMenuFile, subMenuEdit, subMenuView });

            bar2.AddItem(buttonViewOutput);

            barManager.EndUpdate();

            #endregion

            #region 이벤트 동작입니다.

            barManager.ItemClick += barManager_ItemClick;

            #endregion
        }

        #endregion

        #region barManager_ItemClick(sender, e) - Bar 아이템 클릭시 동작합니다.
        /// <summary>
        /// Bar 아이템 클릭시 동작합니다.
        /// </summary>
        /// <param name="sender">이벤트 발생자 입니다.</param>
        /// <param name="e">이벤트 인자 입니다.</param>
        private void barManager_ItemClick(object sender, ItemClickEventArgs e)
        {
            BarSubItem subMenu = e.Item as BarSubItem;

            if(subMenu != null) return;

            MessageBox.Show("Item " + e.Item.Caption + " has been clicked");
        }

        #endregion
    }
}

 

728x90

댓글