C# 仿製QQ彈出新聞訊息框

來源:互聯網
上載者:User

標籤:blog   http   使用   width   os   html   

原文:C# 仿製QQ彈出新聞訊息框

開啟QQ的時候,QQ新聞彈出表單在螢幕的右下角就會慢慢升起一個小視窗,佔用的地方不大,可以起到提示的作用。下面就讓我們來看看,怎樣用系統API來輕鬆實現這個功能。 
API原型函數: 
bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags); 
從字面的意思來看,這個函數名為"活動的視窗",事實上也如此,通過這個函數,可以使我們的表單動作豐富起來,要在c#中使用winApi首先引入命名空間: 

view plaincopy to clipboardprint? 
//引入命名空間    
using System.Runtime.InteropServices;   
//API原型   
[DllImport("user32.dll")]   
private static extern bool AnimateWindow(IntPtr hwnd, int dateTime, int dwFlags);//hwnd視窗控制代碼.dateTime:動畫時間長度.dwFlags:動畫類型組合  
        //引入命名空間 
        using System.Runtime.InteropServices; 
        //API原型 
        [DllImport("user32.dll")] 
        private static extern bool AnimateWindow(IntPtr hwnd, int dateTime, int dwFlags);//hwnd視窗控制代碼.dateTime:動畫時間長度.dwFlags:動畫類型組合 

下面是dwFlags的各種動畫標誌: 

view plaincopy to clipboardprint? 
int AW_ACTIVE = 0x20000; //啟用視窗,在使用了AW_HIDE標誌後不要使用這個標誌   
int AW_HIDE = 0x10000;//隱藏視窗   
int AW_BLEND = 0x80000;// 使用淡入淡出效果   
int AW_SLIDE = 0x40000;//使用滑動類型動畫效果,預設為滾動動畫類型,當使用AW_CENTER標誌時,這個標誌就被忽略   
int AW_CENTER = 0x0010;//若使用了AW_HIDE標誌,則使視窗向內重疊;否則向外擴充   
int AW_HOR_POSITIVE = 0x0001;//自左向右顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌   
int AW_HOR_NEGATIVE = 0x0002;//自右向左顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌   
int AW_VER_POSITIVE = 0x0004;//自頂向下顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌   
int AW_VER_NEGATIVE = 0x0008;//自下向上顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌  
        int AW_ACTIVE = 0x20000; //啟用視窗,在使用了AW_HIDE標誌後不要使用這個標誌 
        int AW_HIDE = 0x10000;//隱藏視窗 
        int AW_BLEND = 0x80000;// 使用淡入淡出效果 
        int AW_SLIDE = 0x40000;//使用滑動類型動畫效果,預設為滾動動畫類型,當使用AW_CENTER標誌時,這個標誌就被忽略 
        int AW_CENTER = 0x0010;//若使用了AW_HIDE標誌,則使視窗向內重疊;否則向外擴充 
        int AW_HOR_POSITIVE = 0x0001;//自左向右顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌 
        int AW_HOR_NEGATIVE = 0x0002;//自右向左顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌 
        int AW_VER_POSITIVE = 0x0004;//自頂向下顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌 
        int AW_VER_NEGATIVE = 0x0008;//自下向上顯示視窗,該標誌可以在滾動動畫和滑動動畫中使用。使用AW_CENTER標誌時忽略該標誌 


申明變數儲存表單顯示的座標: 

view plaincopy to clipboardprint? 
private int currentX;//橫座標      
private int currentY;//縱座標      
private int screenHeight;//螢幕高度      
private int screenWidth;//螢幕寬度    
       private int currentX;//橫座標   
        private int currentY;//縱座標   
        private int screenHeight;//螢幕高度   
        private int screenWidth;//螢幕寬度 
   

load事件中執行動畫: 

view plaincopy to clipboardprint? 
Rectangle rect = Screen.PrimaryScreen.WorkingArea;   
screenHeight = rect.Height;   
screenWidth = rect.Width;   
currentX = screenWidth - this.Width;   
currentY = screenHeight - this.Height;   
this.Location = new System.Drawing.Point(currentX, currentY);   
  
AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_VER_NEGATIVE);  
            Rectangle rect = Screen.PrimaryScreen.WorkingArea; 
            screenHeight = rect.Height; 
            screenWidth = rect.Width; 
            currentX = screenWidth - this.Width; 
            currentY = screenHeight - this.Height; 
            this.Location = new System.Drawing.Point(currentX, currentY); 

            AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_VER_NEGATIVE); 

試試吧! 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.