• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • Microsoft .NET 框架資源基礎

    發表于:2009-08-17來源:作者:點擊數: 標簽:框架NetNETMicrosoft資源
    Microsoft .NET 框架資源基礎 .NET 框架 關鍵字:.NET 假設要在應用程序中通過從文件加載位圖來設置窗體的背景圖像: public Form1() { ... // Load a file from the file system this.BackgroundImage = new Bitmap(@"C:\ WINDOWS \Web\Wallpaper\Azul.jpg"

    Microsoft .NET 框架資源基礎 .NET 框架

    關鍵字:.NET

    假設要在應用程序中通過從文件加載位圖來設置窗體的背景圖像:

    public Form1() {  ...  // Load a file from the file system  this.BackgroundImage =    new Bitmap(@"C:\WINDOWS\Web\Wallpaper\Azul.jpg");}

    該代碼的問題是,并非所有 Microsoft Windows 的安裝實例都有 Azul.jpg,即使是那些確實具有該文件的安裝實例,該文件可能也不在安裝實例的相同位置。即使您與應用程序一起交付該圖片,節省空間的用戶也可能決定刪除它,這會導致您的應用程序出錯。確保圖片或任何文件與代碼在一起的唯一安全方式是將它作為資源嵌入并加載。

    清單資源

    資源是在編譯時添加到程序集中的。例如,如果您使用命令行編譯器,則可以使用 /resource 開關嵌入資源:

    C:\>csc.exe myApp.cs /resource:c:\windows\web\wallpaper\Azul.jpg

    /resource 開關將文件作為資源嵌入,嵌入時使用文件名(沒有路徑)作為資源名稱。文件嵌入到程序集的清單 資源集中。程序集的清單由一組作為程序集一部分的元數據組成。該元數據的一部分是與每個嵌入資源關聯的名稱和數據。執行 ildasm 時,可以在清單部分看見程序集清單資源的列表,如圖 1 所示。

    C:\>ildasm.exe myApp.exe
    winforms02202003-fig01

    圖 1. ildasm 顯示嵌入資源

    可以像 ildasm 一樣枚舉清單資源的列表,這需要使用 System.Reflection.Assembly 類的 GetManifestResourceNames 方法:

    using System.Reflection;...// Get this type's assemblyAssembly assem = this.GetType().Assembly;// Enumerate the assembly's manifest resourcesforeach( string resourceName in assem.GetManifestResourceNames() ) {  MessageBox.Show(resourceName);}

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>