C#, tray notify test

네이트온 메신저에서 메시지가 온 경우 알림을 주는 것과 같이 알림을 주는 트레이알림 테스트 코드.
근데 이벤트 처리가 제대로 안된다 -_-;;;
다른 방식으로 처리를 해야하나,,,,,,,,
혹시 아는 분이 있으면 댓글을 달아주면 좋겠는데

label에 이벤트를 추가했어야하는데,, 그걸 안했었네 -_-
이제는 잘 되지만 정리된 코드는 아니라는 거.

/***********************************************************

*
*     C# notify window at tray test code_revision
*     notifyWindowTest.cs 
*
************************************************************/
using System;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;



namespace notifyWindowTest
{
    class TrayNotifyWindow
    {
        Form nForm = new Form();
        Label notiLabel;

        int mywidth;
        int myheight;

        Thread t1;

        public static ManualResetEvent allDone = new ManualResetEvent(false);


        public TrayNotifyWindow()
        {
            initLabel("[Received a file]");
            initNotifyForm();
            //nForm.MouseClick += nForm_MouseClick;
        }

        public TrayNotifyWindow(string a_fileName)
        {
            initLabel("[Received a file]\n" +"File:"+ a_fileName);

            initNotifyForm();
        }

        public TrayNotifyWindow(string a_fileName, string a_fileSize)
        {
            initLabel("[Received a file]\n" +"File:"+ a_fileName + "\nSize:" + a_fileSize);
            initNotifyForm();
        }

        private void initLabel(string a_text)
        {
            notiLabel = new Label();
            notiLabel.Text = a_text;
            notiLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            notiLabel.Location = new System.Drawing.Point(10, 30);
            notiLabel.Size = new System.Drawing.Size(200, 40);
            nForm.Controls.Add(notiLabel);
        }


        private void initNotifyForm()
        {
            nForm.TopMost = true;
            nForm.ControlBox = false;
            nForm.ClientSize = new System.Drawing.Size(220, 100);

            // set values to change start point
            nForm.StartPosition = FormStartPosition.Manual;

            mywidth = Screen.PrimaryScreen.WorkingArea.Width - nForm.Width;
            myheight = Screen.PrimaryScreen.WorkingArea.Height - nForm.Height;

            nForm.Location = new System.Drawing.Point(mywidth, myheight);
        }

        private void nForm_MouseClick(object sender, EventArgs e)
        {
            System.Windows.Forms.MessageBox.Show("Click");
        }

        public void showNotifyWindow()
        {
            startThread();
        }

        private void stopThread()
        {
            t1.Abort();
        }


        private void startThread()
        {
            t1 = new Thread(new ThreadStart(StartNotify));
            t1.Start();
        }

        private void StartNotify()
        {
            
            nForm.MouseClick += nForm_MouseClick;
            notiLabel.MouseClick += nForm_MouseClick;

            int absolute_y, moving_y;
            
            absolute_y = Screen.PrimaryScreen.WorkingArea.Height;

            moving_y = absolute_y;

            // going up~
            while (moving_y > myheight)
            {
                moving_y -= 1;
                moveNotify(moving_y);
                
                //sleep
                System.Threading.Thread.Sleep(25);                

               // Application.DoEvents();
            }
                        
            // remain for 3 sec
            System.Threading.Thread.Sleep(1500);            
            //Application.DoEvents();

            // going down~
            while (moving_y < absolute_y)
            {
                moving_y += 1;
                moveNotify(moving_y);
                
                //sleep
                System.Threading.Thread.Sleep(25);

               // Application.DoEvents();
            }

            // when finished Notify, abort the thread.            
            stopThread();

            // and dispose nForm
            nForm.Dispose();


        }

        private void moveNotify(int a_height)
        {

            nForm.Location = new System.Drawing.Point(mywidth, a_height);

            nForm.Cursor = Cursors.Hand;
            nForm.Visible = true;
            //Application.DoEvents();
            nForm.Refresh();
            Application.DoEvents();
        }
    }
}

댓글 없음:

댓글 쓰기

안녕하세요 :)