c#桌面應用程序如何添加彈出式廣告

c#寫的軟件不少,如何添加諸如像搜狗輸入法軟件與靈格斯翻譯軟件的屏幕右下角彈出式廣告呢。 c#代碼以下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;c#

using System.Runtime.InteropServices;函數

namespace dataSource { /// <summary> /// 枚舉,描述消息窗口加載的形式 /// </summary> public enum LoadMode { /// <summary> /// 警告 /// </summary> Warning,動畫

/// <summary>
    /// 錯誤
    /// </summary>
    Error,

    /// <summary>
    /// 提示
    /// </summary>
    Prompt
}

/// <summary>
/// 消息提示窗口

/// </summary> public partial class FormMessageBox : Form { /// <summary> /// 構造方法 /// </summary> public FormMessageBox() { InitializeComponent(); }this

#region ***********************字 段***********************

    /// <summary>
    /// 窗體加載模式
    /// </summary>
    private static LoadMode FormMode = LoadMode.Prompt;

    /// <summary>
    /// 顯示的消息正文
    /// </summary>
    private static string ShowMessage = null;

    /// <summary>
    /// 關閉窗口的定時器
    /// </summary>
    private Timer Timer_Close = new Timer();

/// <summary> /// 構造方法 /// </summary> public FormMessageBox() { [DllImportAttribute("user32.dll")] private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags); // 該函數能夠實現窗體的動畫效果spa

public const Int32 AW_HOR_POSITIVE = 0x00000001;   // 自左向右顯示窗口。該標誌能夠在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略 
    public const Int32 AW_HOR_NEGATIVE = 0x00000002;   // 自右向左顯示窗口。當使用了 AW_CENTER 標誌時該標誌被忽略

    public const Int32 AW_VER_POSITIVE = 0x00000004;   // 自頂向下顯示窗口。該標誌能夠在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略
    public const Int32 AW_VER_NEGATIVE = 0x00000008;   // 自下向上顯示窗口。該標誌能夠在滾動動畫和滑動動畫中使用。當使用AW_CENTER標誌時,該標誌將被忽略

    public const Int32 AW_CENTER = 0x00000010;         // 若使用了AW_HIDE標誌,則使窗口向內重疊;若未使用AW_HIDE標誌,則使窗口向外擴展
    public const Int32 AW_HIDE = 0x00010000;           // 隱藏窗口,缺省則顯示窗口
    public const Int32 AW_ACTIVATE = 0x00020000;       // 激活窗口。在使用了AW_HIDE標誌後不要使用這個標誌
    public const Int32 AW_SLIDE = 0x00040000;          // 使用滑動類型。缺省則爲滾動動畫類型。當使用AW_CENTER標誌時,這個標誌就被忽略
    public const Int32 AW_BLEND = 0x00080000;          // 使用淡入效果。只有當hWnd爲頂層窗口的時候纔可使用此標誌

    #endregion*************************************************


    #region ***********************方 法***********************

    /// <summary>
    /// 構造方法
    /// </summary>
    /// <param name="loadMode">加載模式</param>
    /// <param name="message">消息正文</param>

    public static void Show(LoadMode loadMode, string message)
        InitializeComponent();
    }


    #region ***********************字 段***********************

    /// <summary>
    /// 窗體加載模式
    /// </summary>
    private static LoadMode FormMode = LoadMode.Prompt;

    /// <summary>
    /// 顯示的消息正文
    /// </summary>
    private static string ShowMessage = null;

    /// <summary>
    /// 關閉窗口的定時器
    /// </summary>
    private Timer Timer_Close = new Timer();

FormMode = loadMode; ShowMessage = message;翻譯

FormMessageBox box = new FormMessageBox();
        box.Show();
    }



    #endregion*************************************************


    #region ***********************事 件***********************

    /// <summary>
    /// 窗體加載事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void FormMessageBox_Load(object sender, EventArgs e)
    {
        this.lblTitle.Text = "提示";
        if (FormMode == LoadMode.Error)
        {
            this.lblTitle.Text = "錯誤";
            this.plShow.BackgroundImage = global::dataSource.Properties.Resources.error;    // 更換背景
        }
        else if (FormMode == LoadMode.Warning)
        {
            this.lblTitle.Text = "警告";
            this.plShow.BackgroundImage = global::dataSource.Properties.Resources.warning;  // 更換背景
        }
        else

{ this.plShow.BackgroundImage = global::dataSource.Properties.Resources.Prompt; // 更換背景 }code

this.lblMessage.Text = ShowMessage;

        int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
        int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
        int top = height - 35 - this.Height;
        int left = width - this.Width - 5;
        this.Top = top;
        this.Left = left;
        this.TopMost = true;

        AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_NEGATIVE);//開始窗體動畫

        this.ShowInTaskbar = false;

        Timer_Close.Interval = 4000;
        Timer_Close.Tick += new EventHandler(Timer_Close_Tick);
        Timer_Close.Start();
    }

    /// <summary>
    /// 關閉窗口的定時器響應事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Timer_Close_Tick(object sender, EventArgs e)
    {
        Timer_Close.Stop();

        this.Close();

/// <summary> /// 窗口已經關閉 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormMessageBox_FormClosed(object sender, FormClosedEventArgs e) { AnimateWindow(this.Handle, 500, AW_SLIDE + AW_VER_POSITIVE + AW_HIDE);orm

Timer_Close.Stop();
        Timer_Close.Dispose();
    }

    /// <summary>
    /// 鼠標移動在消息框上
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void plShow_MouseMove(object sender, MouseEventArgs e)
    {
        this.Timer_Close.Stop();
    }

    /// <summary>
    /// 鼠標移動離開消息框上
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void plShow_MouseLeave(object sender, EventArgs e)
    {
        this.Timer_Close.Start();
    }

#endregion************************************************* 代碼已經徹底提供事件

相關文章
相關標籤/搜索