winform實現的仿Msn移動提示資訊視窗

來源:互聯網
上載者:User
有些軟體在某個特定的時間會顯示一個提示表單,這個表單不是直接顯示的,而是慢慢從視窗的最下方向上移動,直至表單完全顯示就不再移動。當我們點擊“確定”按鈕之後,表單由從螢幕上逐漸下移,直至完全從螢幕上完全不顯示。這也是本文討論的表單效果之一:winform實現的移動提示資訊視窗。
每個Control類都有一個Location屬性,它是一個Point值,這個值表示控制項的左上方的座標值,利用這個座標值,我們可以設定表單的位置。程式核心代碼如下:  
using System;   
using System.Collections.Generic;   
using System.ComponentModel;    
using System.Data;    
using System.Drawing;   
using System.Text;    
using System.Windows.Forms;     
namespace ThreadDemo    
{    
    /// <summary>    
    /// 說明:這是資訊提示視窗,運行程式的時候,這個視窗會緩慢從螢幕下方  
    /// 向上移動,知道提示資訊視窗完全顯示;    
    /// 當點擊“確定”按鈕之後,這個視窗又會緩慢從螢幕地區移出  
   /// </summary>    
    public partial class NoteForm : Form    
    {    
        private int screenWidth;//螢幕寬度    
        private int screenHeight;//螢幕高度  
          private bool finished=false;//是否完全顯示提示視窗   
        public NoteForm()    
        {    
            InitializeComponent();    
            screenHeight = Screen.PrimaryScreen.Bounds.Height;    
            screenWidth = Screen.PrimaryScreen.Bounds.Width;   
            //設定提示視窗座標在螢幕可顯示地區之外    
            Location = new Point(screenWidth-Width, screenHeight);   
        }  
          private void NoteForm_Load(object sender, EventArgs e)   
        {    
        }    
       private void timer1_Tick(object sender, EventArgs e)    
        {    
            if (!finished)//如果提示視窗沒有完全顯示   
            {    
                //如果提示視窗的縱座標與提示視窗的高度之和大於螢幕高度    
                if (Location.Y + Height >= screenHeight)
                  {    
                    Location = new Point(Location.X, Location.Y - 5);    
                }    
            }    
            else//如果提示視窗已經完成了顯示,並且點擊了確定按鈕    
            {    
                //如果提示視窗沒有完全從螢幕上消失    
                if (Location.Y < screenHeight)    
                {    
                    Location = new Point(Location.X, Location.Y + 5);  
                }    
            }    
        }    
        private void btnOK_Click(object sender, EventArgs e)   
        {    
            //設定完成了顯示,以便讓提示控制項移出螢幕可顯示地區    
            finished = true;    
        }    
    }   
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.