C# 界面从无到有 从有到无

来源:互联网 发布:js判断ie浏览器 编辑:程序博客网 时间:2024/06/06 00:01

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Threading;
//using NetBLL;

namespace shengqi
{
    public partial class Form1 : Form
    {
        public delegate void SetTime1();//声明委托
        public delegate void SetTime2();
        public delegate void SetTime3();
        public delegate void SetTime4();
        public delegate void SetTimeClose();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Top = Screen.PrimaryScreen.Bounds.Height;//得到高
            this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;//得到X坐标
            Thread th1 = new Thread(new ThreadStart(setTime1Run));//绑定改变坐标的方法
            Thread th2 = new Thread(new ThreadStart(setTime2Run));//绑定改变坐标的方法
            //设置为后台线程
            th1.IsBackground = true;
            th2.IsBackground = true;

            th1.Priority = ThreadPriority.Highest;//设置优先级
            //起启动线程
            th1.Start();
            th2.Start();
        }

        public void setTime1Run()
        {
            Thread.Sleep(500);
            while (this.Bottom > Screen.PrimaryScreen.WorkingArea.Height)//从无到有
            {               

                if (this.InvokeRequired)
                {
                    this.Invoke(new SetTime3(lowerTop));
                }
                else
                {
                    this.Top--;
                }

                Thread.Sleep(10);
            }
        }

        public void lowerTop()
        {
            this.Top--;
        }

        public void setTime2Run()
        {
            Thread.Sleep(6000);
            while (this.Top < Screen.PrimaryScreen.Bounds.Height)//从有到无
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new SetTime4(falloff));
                }
                else
                {
                    this.Top++;
                }
                Thread.Sleep(10);
               
            }
            if (this.InvokeRequired)
            {
                this.Invoke(new SetTimeClose(closeForm));
            }
            else
            {
                this.Close();
            }
        }
        public void falloff()
        {
            this.Top++;
        }
        public void closeForm()
        {
            this.Close();
        }
    }
}

原创粉丝点击