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

■ TransitionManager 클래스 : 컨트롤 상태 변경시 애니메이션 사용하기

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


TestProject.zip


MainForm.cs

 

 

using System;

using System.Drawing;

using System.Windows.Forms;

 

using DevExpress.Data.Utils;

using DevExpress.Utils.Animation;

using DevExpress.XtraEditors;

using DevExpress.XtraTab;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : XtraForm

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region Field

 

        /// <summary>

        /// 애니메이션 컨트롤

        /// </summary>

        private Control controlToAnimate;

 

        /// <summary>

        /// 이징 함수

        /// </summary>

        private IEasingFunction easingFunction = new BackEase();

 

        #endregion

 

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

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

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            #region 이행 관리자를 설정한다.

 

            this.transitionManager.ShowWaitingIndicator = false;

 

            #endregion

            #region 이행 타입 이미지 콤보 박스 에디터를 설정한다.

 

            this.transitionTypeComboBoxEdit.Properties.Items.AddEnum(typeof(Transitions));

 

            #endregion

            #region 이벤트를 설정한다.

 

            Load                                                      += Form_Load;

            this.transitionManager.CustomTransition                   += transitionManager_CustomTransition;

            this.transitionTypeComboBoxEdit.SelectedIndexChanged += transitionTypeComboBoxEdit_SelectedIndexChanged;

            this.xtraTabControl.SelectedPageChanging                  += xtraTabControl_SelectedPageChanging;

            this.xtraTabControl.SelectedPageChanged                   += xtraTabControl_SelectedPageChanged;

 

            #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        //////////////////////////////////////////////////////////////////////////////// Event

 

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

 

        /// <summary>

        /// 폼 로드시 처리하기

        /// </summary>

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

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

        private void Form_Load(object sender, EventArgs e)

        {

            this.controlToAnimate = this.xtraTabControl;

 

            this.transitionTypeComboBoxEdit.SelectedIndex = 0;

        }

 

        #endregion

        #region 이행 관리자 커스텀 이행 처리하기 - transitionManager_CustomTransition(transition, e)

 

        /// <summary>

        /// 이행 관리자 커스텀 이행 처리하기

        /// </summary>

        /// <param name="transition">이행</param>

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

        private void transitionManager_CustomTransition(ITransition transition, CustomTransitionEventArgs e)

        {

            e.Regions = new Rectangle[] { this.xtraTabPage1.Bounds };

 

            e.EasingFunction = easingFunction;

        }

 

        #endregion

        #region 이행 타입 콤보 박스 에디터 선택 인덱스 변경시 처리하기 - transitionTypeComboBoxEdit_SelectedIndexChanged(sender, e)

 

        /// <summary>

        /// 이행 타입 콤보 박스 에디터 선택 인덱스 변경시 처리하기

        /// </summary>

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

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

        private void transitionTypeComboBoxEdit_SelectedIndexChanged(object sender, EventArgs e)

        {

            ImageComboBoxEdit imageComboBoxEdit = sender as ImageComboBoxEdit;

 

            if(this.transitionManager.Transitions[controlToAnimate] == null)

            {

                Transition transition = new Transition();

 

                transition.Control = controlToAnimate;

 

                this.transitionManager.Transitions.Add(transition);

            }

 

            Transitions transitions = (Transitions)imageComboBoxEdit.EditValue;

 

            this.transitionManager.Transitions[controlToAnimate].TransitionType = GetTransition(transitions);

        }

 

        #endregion

        #region XTRA 탭 컨트롤 선택 페이지 변경전 처리하기 - xtraTabControl_SelectedPageChanging(sender, e)

 

        /// <summary>

        /// XTRA 탭 컨트롤 선택 페이지 변경전 처리하기

        /// </summary>

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

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

        private void xtraTabControl_SelectedPageChanging(object sender, TabPageChangingEventArgs e)

        {

            if(this.controlToAnimate == null)

            {

                return;

            }

 

            this.transitionManager.StartTransition(this.controlToAnimate);

        }

 

        #endregion

        #region XTRA 탭 컨트롤 선택 페이지 변경후 처리하기 - xtraTabControl_SelectedPageChanged(sender, e)

 

        /// <summary>

        /// XTRA 탭 컨트롤 선택 페이지 변경후 처리하기

        /// </summary>

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

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

        private void xtraTabControl_SelectedPageChanged(object sender, TabPageChangedEventArgs e)

        {

            this.transitionManager.EndTransition();

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////// Function

 

        #region 이행 구하기 - GetTransition(transitions)

 

        /// <summary>

        /// 이행 구하기

        /// </summary>

        /// <param name="transitions">이행 타입</param>

        /// <returns>이행</returns>

        private BaseTransition GetTransition(Transitions transitions)

        {

            switch(transitions)

            {

                case Transitions.Dissolve  : return new DissolveTransition();

                case Transitions.Fade      : return new FadeTransition();

                case Transitions.Shape     : return new ShapeTransition();

                case Transitions.Clock     : return new ClockTransition();

                case Transitions.SlideFade : return new SlideFadeTransition();

                case Transitions.Cover     : return new CoverTransition();

                case Transitions.Comb      : return new CombTransition();

                default                    : return new PushTransition();

            }

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요