퇴근5분전



  내부 컨텐츠를 변경하는 방법을 구현한 것임.

매번 쓸때마다 구현하기도 구찮긴 한뎅... 이제 플그램 많이 안할것 같으니 적어만 둔다.


public partial class Form1 : Form
    {
        List<Control> Contents = new List<Control>();
      int currentControlIndex = 0;

        public Form1()
        {
            InitializeComponent();
            Contents.Add(new ContenControl() { Text = "TXT01" });
            Contents.Add(new ContenControl() { Text = "TXT02" });
            Contents.Add(new ContenControl() { Text = "TXT03" });
            Contents.Add(new ContenControl() { Text = "TXT04" });
            Contents.Add(new ContenControl() { Text = "TXT05" });
            Contents.Add(new ContenControl() { Text = "TXT06" });
            Contents.Add(new ContenControl() { Text = "TXT07" });
            Contents.Add(new ContenControl() { Text = "TXT08" });

            foreach (Control ctrl in Contents)
            {
                this.panel1.Controls.Add(ctrl);
            }
            UpdateButtonStates();
        }

        private void NextBtn_Click(object sender, EventArgs e)
        {
            // Next
            Control Current = GetContentControl(+1);
            Current.BringToFront();
            UpdateButtonStates();
        }

        private void UpdateButtonStates()
        {
            NextBtn.Enabled = currentControlIndex < Contents.Count - 1;
            PrevBtn.Enabled = 0 < currentControlIndex;
        }

        private Control GetContentControl(int idx)
        {
            Control ctrl = Contents[currentControlIndex];
            if (idx < 0)
            {
                if (currentControlIndex + idx < 0)
                {
                    idx = 0;
                }
            }
            else if (0 < idx)
            {
                if (Contents.Count - 1 < currentControlIndex + idx)
                {
                    idx = Contents.Count - 1;
                }
            }
            currentControlIndex = currentControlIndex + idx;
            ctrl = Contents[ currentControlIndex ];
            return ctrl;
        }

        private void PrevBtn_Click(object sender, EventArgs e)
        {
            // Prev
            Control Current = GetContentControl(-1);
            Current.BringToFront();
            UpdateButtonStates();
        }
    }


    public class ContenControl : UserControl
    {
        Label lb = new Label();
        public ContenControl()
        {
            this.lb.BorderStyle = BorderStyle.FixedSingle;
            lb.AutoSize = false;
            lb.TextAlign = ContentAlignment.MiddleCenter;
            lb.Dock = DockStyle.Fill;
            this.Controls.Add(lb);
            this.BorderStyle = BorderStyle.FixedSingle;
            this.Dock = DockStyle.Fill;
        }

        public override string Text
        {
            get
            {
                return lb.Text;
            }
            set
            {
                lb.Text = value;
            }
        }
    }

'# 3) .Net ( Vs 2008 ) > C#' 카테고리의 다른 글

ClickOnce UpdateAsync ~!!  (0) 2011.10.31
LINQ] GroupBy  (0) 2011.10.12
Vs2008] 성능 카운터  (0) 2011.08.16
vs2008] WMI 관련..  (0) 2011.08.16
노트북 셋팅..  (0) 2011.08.02