첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ BarManager 클래스 : MDI 병합하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


ChildForm.cs

 

 

 

using DevExpress.XtraEditors;

 

namespace TestProject

{

    /// <summary>

    /// 자식 폼

    /// </summary>

    public partial class ChildForm : XtraForm

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - ChildForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public ChildForm()

        {

            InitializeComponent();

        }

 

        #endregion

    }

}

 

 

MainForm.cs

 

 

 

using System;

using System.Drawing;

 

using DevExpress.XtraBars;

using DevExpress.XtraEditors;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : XtraForm

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            Load                    += Form_Load;

            this.barManager.Merge   += barManager_Merge;

            this.barManager.UnMerge += barManager_UnMerge;

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

 

        /// <summary>

        /// 폼 로드시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Form_Load(object sender, EventArgs e)

        {

            ChildForm form1 = new ChildForm();

 

            form1.MdiParent = this;

            form1.Text      = "툴바 자식 폼 1";

 

            form1.Show();

 

            XtraForm form2 = new XtraForm();

 

            form2.MdiParent = this;

            form2.Size      = new Size(400, 300);

            form2.Text      = "자식 폼 1";

 

            form2.Show();

 

            ChildForm form3 = new ChildForm();

            

            form3.MdiParent = this;

            form3.Text      = "툴바 자식 폼 2";

            

            form3.Show();

        }

 

        #endregion

        #region 바 관리자 병합시 처리하기 - barManager_Merge(sender, e)

 

        /// <summary>

        /// 바 관리자 병합시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void barManager_Merge(object sender, BarManagerMergeEventArgs e)

        {

            BarManager barManager = sender as BarManager;

 

            barManager.BeginUpdate();

 

            if(e.ChildManager.Form is ChildForm)

            {

                Bar parentToolBar1 = new Bar()

                {

                    BarName   = "ParentToolBar1",

                    Text      = "ParentToolBar1",

                    DockStyle = BarDockStyle.Top,

                    DockRow   = barManager.Bars["ToolBar"].DockRow,

                    DockCol   = 2

                };

 

                Bar parentToolBar2 = new Bar()

                {

                    BarName   = "ParentToolBar2",

                    Text      = "ParentToolBar2",

                    DockStyle = BarDockStyle.Top,

                    DockRow   = barManager.Bars["ToolBar"].DockRow,

                    DockCol   = 3

                };

 

                barManager.Bars.AddRange(new Bar[] { parentToolBar1, parentToolBar2 });

 

                barManager.Bars["ParentToolBar1"].Merge(e.ChildManager.Bars["ToolBar1"]);

                barManager.Bars["ParentToolBar2"].Merge(e.ChildManager.Bars["ToolBar2"]);

 

                barManager.StatusBar.Merge(e.ChildManager.StatusBar);

            }

 

            barManager.EndUpdate();

        }

 

        #endregion

        #region 바 관리자 병합 취소시 처리하기 - barManager_UnMerge(sender, e)

 

        /// <summary>

        /// 바 관리자 병합 취소시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void barManager_UnMerge(object sender, BarManagerMergeEventArgs e)

        {

            BarManager barManager = sender as BarManager;

 

            barManager.BeginUpdate();

 

            if(e.ChildManager.Form is ChildForm)

            {

                barManager.Bars["ParentToolBar1"].UnMerge();

                barManager.Bars["ParentToolBar2"].UnMerge();

 

                barManager.Bars["ParentToolBar1"].Dispose();

                barManager.Bars["ParentToolBar2"].Dispose();

 

                barManager.StatusBar.UnMerge();

            }

 

            barManager.EndUpdate();

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요