[C#] Form을 활성화하기

http://chaoskcuf.com/entry/C-HTML-ltselectgt-option-동적으로-바꾸기#comment3086 코멘트에 대한 답변입니다.

    public partial class Form1 : Form
    {
        Timer _timer = new Timer();
        public Form1()
        {
            InitializeComponent();
            _timer.Interval = 2000;
            _timer.Tick += new EventHandler(_timer_Tick);
            _timer.Start();
        }

        void _timer_Tick(object sender, EventArgs e)
        {
            if(this.WindowState == FormWindowState.Minimized)
            {
                this.WindowState = FormWindowState.Normal;
            }
            this.Activate();
        }
    }

위의 코드는 Timer를 사용하여 2초마다 창을 활성화(화면의 맨 앞으로 오게) 만드는 것입니다.

Form 클래스에는 Activate() 라는 함수가 있는데요.
이 함수를 사용하면 됩니다.

단, 여기서 한가지 주의 하실 점은 Form이 최소화 되어 있을 때는 활성화 되지 않으니 Form의 창 상태
즉, WindowState를 Normal로 변경해 주어야 합니다.

짧은 코드니까 쉽게 이해하실 수 있으실 겁니다. ^^

chaoskcuf
프로그래밍/TIP& Study 2008/11/14 10:33

트랙백 주소 : http://chaoskcuf.com/trackback/170

댓글을 달아 주세요

Powerd by Textcube, designed by criuce
rss