亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#使用AnimateWindow()實現(xiàn)動畫窗體的方法

 更新時間:2024年04月21日 11:42:17   作者:wenchm  
用API函數(shù)AnimateWindow函數(shù)來實現(xiàn)窗體的動畫效果,在C#中,你可以使用P/Invoke技術(shù)調(diào)用Windows API中的AnimateWindow函數(shù)來實現(xiàn)動畫窗體,本文就給大家介紹了C#使用AnimateWindow()實現(xiàn)動畫窗體的方法,感興趣的朋友可以參考下

一.涉及到的知識點

(1) AnimateWindow函數(shù)

用API函數(shù)AnimateWindow函數(shù)來實現(xiàn)窗體的動畫效果。在C#中,你可以使用P/Invoke技術(shù)調(diào)用Windows API中的AnimateWindow函數(shù)來實現(xiàn)動畫窗體。語法格式如下:

[DllImportAttribute("user32.dll")]
private static extern bool Animate Window(IntPtr hwnd,int dwTime,int dwFlags);參數(shù)說明
hwnd:IntPtr,窗口句柄。
dwTime:動畫的持續(xù)時間,數(shù)值越大動畫效果的時間就越長。
dwFlags:動畫效果類型選項,其常量值及說明如表:

    

   

AW_SLIDE

0x0004000

使用滑動類型。默認(rèn)則為滾動動畫類型。當(dāng)使用AW_CENTER標(biāo)志時,這個標(biāo)志就被忽略

AW_ACTIVATE

0x00020000

激活窗口。在使用AW_HIDE標(biāo)志后不要使用這個標(biāo)志

AW_BLEND

0x00080000

使用淡入效果。只有當(dāng)hWnd為頂層窗口時才可以使用此標(biāo)志

AW_HIDE

0x00010000

隱藏窗口,默認(rèn)則顯示窗口

AW_CENTER

0x00000010

若使用AW_HIDE標(biāo)志,則使窗口向內(nèi)重疊;若未使用AW_HIDE標(biāo)志,則使窗口向外擴(kuò)展

AW_HOR_POSITIVE

0x00000001

自左向右顯示窗口。該標(biāo)志可以在滾動動畫和滑動動畫中使用。當(dāng)使用AW_CENTER標(biāo)志時,該標(biāo)志將被忽略

AW_HOR_NEGATIVE

0x00000002

自右向左顯示窗口。當(dāng)使用AW_CENTER標(biāo)志時該標(biāo)志被忽略

AW_VER_POSITIVE

0x00000004

自頂向下顯示窗口。該標(biāo)志可以在滾動動畫和滑動動畫中使用。當(dāng)使用AW_CENTER標(biāo)志時,該標(biāo)志將被忽略

AW_VER_NEGATIVE

0x00000008

自下向上顯示窗口。該標(biāo)志可以在滾動動畫和滑動動畫中使用。當(dāng)使用AW_CENTER標(biāo)志時,該標(biāo)志將被忽略

(2)操作流程

1.首先,定義一個用于封裝AnimateWindow函數(shù)的類

 public static partial class Animations
 {
     [LibraryImport("user32.dll", SetLastError = true)]
     [return: MarshalAs(UnmanagedType.Bool)]
     public static partial bool AnimateWindow(IntPtr hWnd, int dwTime, int dwFlags);
 }

2.在窗體類中使用這個方法

 private void Form1_Load(object sender, EventArgs e)
 {
     Animations.AnimateWindow(Handle, 500, (int)AnimationFlags.AW_HOR_POSITIVE | (int)AnimationFlags.AW_VER_POSITIVE);
 }
 
 [Flags]
 public enum AnimationFlags
 {
     AW_HOR_POSITIVE = 0x0001,
     AW_HOR_NEGATIVE = 0x0002,
     AW_VER_POSITIVE = 0x0004,
     AW_VER_NEGATIVE = 0x0008,
     AW_CENTER = 0x0010
 }

3.生成效果

在這個例子中,AW_HOR_POSITIVE 和 AW_VER_POSITIVE 標(biāo)志表示窗口將從左上角向右下角展開。

二、實例

本實例設(shè)計的是一個動畫顯示的窗體,該程序運(yùn)行后,窗體是慢慢地以拉伸的效果顯示到用戶的面前;窗體關(guān)閉時,也是一樣慢慢地消失。

(1)Resources.Designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     此代碼由工具生成。
//     運(yùn)行時版本:4.0.30319.42000
//
//     對此文件的更改可能會導(dǎo)致不正確的行為,并且如果
//     重新生成代碼,這些更改將會丟失。
// </auto-generated>
//------------------------------------------------------------------------------
 
namespace _189.Properties {
    using System;
    
    
    /// <summary>
    ///   一個強(qiáng)類型的資源類,用于查找本地化的字符串等。
    /// </summary>
    // 此類是由 StronglyTypedResourceBuilder
    // 類通過類似于 ResGen 或 Visual Studio 的工具自動生成的。
    // 若要添加或移除成員,請編輯 .ResX 文件,然后重新運(yùn)行 ResGen
    // (以 /str 作為命令選項),或重新生成 VS 項目。
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources {
        
        private static global::System.Resources.ResourceManager resourceMan;
        
        private static global::System.Globalization.CultureInfo resourceCulture;
        
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources() {
        }
        
        /// <summary>
        ///   返回此類使用的緩存的 ResourceManager 實例。
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_189.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
        
        /// <summary>
        ///   重寫當(dāng)前線程的 CurrentUICulture 屬性,對
        ///   使用此強(qiáng)類型資源類的所有資源查找執(zhí)行重寫。
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 類型的本地化資源。
        /// </summary>
        internal static System.Drawing.Bitmap _03 {
            get {
                object obj = ResourceManager.GetObject("_03", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
    }
}

(2)Form1.Designer.cs

namespace _189
{
    partial class Form1
    {
        /// <summary>
        ///  Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        ///  Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        ///  Required method for Designer support - do not modify
        ///  the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            SuspendLayout();
            // 
            // Form1
            // 
            AutoScaleDimensions = new SizeF(7F, 17F);
            AutoScaleMode = AutoScaleMode.Font;
            BackgroundImage = Properties.Resources._03;
            BackgroundImageLayout = ImageLayout.Stretch;
            ClientSize = new Size(354, 261);
            Name = "Form1";
            StartPosition = FormStartPosition.CenterScreen;
            Text = "動畫窗體";
            FormClosed += Form1_FormClosed;
            Load += Form1_Load;
            ResumeLayout(false);
        }
 
        #endregion
    }
}

(3)Form1.cs

// 動畫窗體
using System.Runtime.InteropServices;
 
namespace _189
{
    public partial class Form1 : Form
    {
        public const Int32 AW_HOR_POSITIVE = 0x00000001;
        public const Int32 AW_HOR_NEGATIVE = 0x00000002;
        public const Int32 AW_VER_POSITIVE = 0x00000004;
        public const Int32 AW_VER_NEGATIVE = 0x00000008;
        public const Int32 AW_CENTER = 0x00000010;
        public const Int32 AW_HIDE = 0x00010000;
        public const Int32 AW_ACTIVATE = 0x00020000;
        public const Int32 AW_SLIDE = 0x00040000;
        public const Int32 AW_BLEND = 0x00080000;
 
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 開始窗體動畫
        /// </summary>
        private void Form1_Load(object sender, EventArgs e)
        {
            AnimateWindow(Handle, 3000, AW_SLIDE + AW_VER_NEGATIVE);
        }
        //重寫API函數(shù),用來執(zhí)行窗體動畫顯示操作
        [LibraryImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static partial bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
        /// <summary>
        /// 結(jié)束窗體動畫
        /// </summary>
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            AnimateWindow(Handle, 3000, AW_SLIDE + AW_VER_NEGATIVE + AW_HIDE);
        }
    }
}

(4)生成的動畫效果

打開和關(guān)閉窗體都會產(chǎn)生動畫效果,可惜動畫無法截圖,網(wǎng)友自己體驗去吧。

以上就是C#使用AnimateWindow()實現(xiàn)動畫窗體的方法的詳細(xì)內(nèi)容,更多關(guān)于C# AnimateWindow()動畫窗體的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • c#中DataTable轉(zhuǎn)List的2種方法示例

    c#中DataTable轉(zhuǎn)List的2種方法示例

    這篇文章主要給大家介紹了關(guān)于c#中DataTable轉(zhuǎn)List的2種方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • C#讀取數(shù)據(jù)庫返回泛型集合詳解(DataSetToList)

    C#讀取數(shù)據(jù)庫返回泛型集合詳解(DataSetToList)

    本篇文章主要是對C#讀取數(shù)據(jù)庫返回泛型集合(DataSetToList)進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • C#實現(xiàn)屬于自己的QQ截圖工具

    C#實現(xiàn)屬于自己的QQ截圖工具

    這篇文章主要為大家詳細(xì)介紹了C#實現(xiàn)屬于自己的QQ截圖工具的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-04-04
  • C#中抽象方法與虛擬方法的區(qū)別

    C#中抽象方法與虛擬方法的區(qū)別

    這篇文章主要介紹了C#中抽象方法與虛擬方法的區(qū)別,對于C#初學(xué)者來說可以深入理解抽象方法與虛擬方法,需要的朋友可以參考下
    2014-08-08
  • C#創(chuàng)建、部署、調(diào)用WebService圖文實例詳解

    C#創(chuàng)建、部署、調(diào)用WebService圖文實例詳解

    本文主要用詳細(xì)的圖文給大家介紹C#創(chuàng)建、部署、調(diào)用WebService的全部過程以及中間需要避免的問題。
    2017-11-11
  • C#實現(xiàn)通過winmm.dll控制聲音播放的方法

    C#實現(xiàn)通過winmm.dll控制聲音播放的方法

    這篇文章主要介紹了C#實現(xiàn)通過winmm.dll控制聲音播放的方法,很實用的功能,需要的朋友可以參考下
    2014-08-08
  • ref與out之間的區(qū)別深入解析

    ref與out之間的區(qū)別深入解析

    以下是對c#中ref與out之間的區(qū)別進(jìn)行了詳細(xì)分析介紹,需要的朋友可以過來參考下
    2013-09-09
  • C# 操作網(wǎng)絡(luò)適配器的示例

    C# 操作網(wǎng)絡(luò)適配器的示例

    這篇文章主要介紹了C# 操作網(wǎng)絡(luò)適配器的示例,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下
    2020-10-10
  • C# AutoResetEvent的具體使用方法

    C# AutoResetEvent的具體使用方法

    AutoResetEvent是C#中的一個同步原語,用于在線程之間傳遞信號,本文主要介紹了C# AutoResetEvent的具體使用方法,具有一定的參考價值,感興趣的可以了解一下
    2025-01-01
  • C#加密在實際中的應(yīng)用

    C#加密在實際中的應(yīng)用

    在系統(tǒng)的管理員有著實際的應(yīng)用,對于一個數(shù)據(jù)庫管理系統(tǒng)來說,數(shù)據(jù)庫安全還是挺重要的,所以在存入到數(shù)據(jù)庫的密碼通常都是加密的
    2012-11-11

最新評論