右下角打开窗体

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;

namespace WindowsApplication3
{
    public partial class ThisShow : Form
    {
        public static  BackgroundWorker worker;
        public ThisShow()
        {
            if (worker == null)
            {
                worker = new BackgroundWorker();
            }
            InitializeComponent();
            worker.WorkerReportsProgress = true;
            worker.WorkerSupportsCancellation = true;
            //正式做事情的地方
            worker.DoWork += new DoWorkEventHandler(DoWork);
            //任务完称时要做的,比如提示等等
            worker.ProgressChanged += new ProgressChangedEventHandler(ProgessChanged);
            //任务进行时,报告进度
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompleteWork);

        }

        //调用 RunWorkerAsync 时发生
        public void DoWork(object sender, DoWorkEventArgs e)
        {
            e.Result = SetFromPosition(worker, e);
            //获取异步操作结果的值,当ComputeFibonacci(worker, e)返回时,异步过程结束
        }

        //调用 ReportProgress 时发生
        public void ProgessChanged(object sender, ProgressChangedEventArgs e)
        {

            this.Location = (Point)e.UserState;
            //this.progressBar1.Value = e.ProgressPercentage;
            //将异步任务进度的百分比赋给进度条

        }

        //当后台操作已完成、被取消或引发异常时发生
        public void CompleteWork(object sender, RunWorkerCompletedEventArgs e)
        {
            this.Close();
        }

        private int SetFromPosition(object sender, DoWorkEventArgs e)
        {
            //判断应用程序是否取消后台操作
            if (worker.CancellationPending)
            {
                e.Cancel = true;
            }
            else
            {
                worker.ReportProgress(0, new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height));
                Thread.Sleep(10);
                for (int i = 0; i <= this.Height + 1; i++)
                {

                    worker.ReportProgress(0 , new Point(this.Location.X, this.Location.Y - 1));
                    Thread.Sleep(5);
                }
                Thread.Sleep(5000);
                for (int i = 0; i <= this.Height + 1; i++)
                {
                    worker.ReportProgress(0, new Point(this.Location.X, this.Location.Y + 1));
                    Thread.Sleep(5);
                }
                this.Close();
            }
            return -1;
        }
        public void Start()
        {
            if (!worker.IsBusy)
            {   
                this.WindowState = FormWindowState.Normal;
                worker.RunWorkerAsync();              
                this.Show();
              
            }
        }

        public void Stop()
        {
            if (worker.IsBusy)
            {
                worker.CancelAsync();
            }
        }

        private void ThisShow_Load(object sender, EventArgs e)
        {

        }

        internal void SetFromPosition()
        {
            this.Location = new System.Drawing.Point(Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height);
            for (int i = 0; i < this.Height + 30; i++)
            {
                this.Location = new Point(this.Location.X, this.Location.Y - 1);
                Thread.Sleep(5);
            }
            for (int i = 0; i < this.Height + 30; i++)
            {
                this.Location = new Point(this.Location.X, this.Location.Y + 1);
                Thread.Sleep(5);
            }
            this.Close();
        }

        private void ThisShow_FormClosed(object sender, FormClosedEventArgs e)
        {
            Stop();
        }
    }
}

 

        private void button3_Click(object sender, EventArgs e)
        {
            ThisShow fm = new ThisShow();
            fm.Start();
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值