共用方式為


Outlook) (Folder.SetCustomIcon 方法

會針對資料夾設定 Picture 所指定的自訂圖示。

語法

運算式SetCustomIcon (圖片)

表達 代表 Folder 物件的 變數。

參數

名稱 必要/選用 資料類型 描述
Picture 必要 IPictureDisp 會指定資料夾的自訂圖示。

註解

Picture指定的IPictureDisp物件的Type屬性必須等於PICTYPE_ICONPICTYPE_BITMAP。 圖示或點陣圖資源的大小上限可以是 32x32。 也支援 16x16 或 24x24 的圖示,如果 Outlook 在 DPI) 模式中以每英吋高點數執行 (,則 Microsoft Outlook 可以相應增加 16x16 圖示。 其他大小的圖示會導致 SetCustomIcon 傳回錯誤。

您可以為搜尋資料夾以及不代表預設或特殊資料夾的所有資料夾設定自訂圖示。 如果您嘗試為屬於下列其中一個資料夾群組的資料夾設定自訂圖示, SetCustomIcon 會傳回錯誤:

  • 預設資料夾 (如 OlDefaultFolders 列舉)
  • OlSpecialFolders列舉 (列示的特殊資料夾)
  • Exchange 公用資料夾
  • 任何 Exchange 信箱的根資料夾
  • 隱藏的資料夾

您只能從以 Outlook 同處理序執行的程式碼呼叫 SetCustomIconIPictureDisp 物件無法跨處理序邊界進行封送處理。 如果您嘗試從跨處理序程式碼呼叫 SetCustomIcon,則會發生例外。

此方法提供的自訂資料夾圖示過了執行中的 Outlook 工作階段之後便不會保留。 因此,增益集必須在 Outlook 每次啟動時,設定自訂資料夾圖示。

自訂資料夾圖示不會出現於其他 Exchange 用戶端 (例如 Outlook Web Access) 中,也不會出現於 Windows Mobile 裝置上執行的 Outlook 中。

範例

The following managed code is written in C#. To run a .NET Framework managed code sample that needs to call into a Component Object Model (COM), you must use an interop assembly that defines and maps managed interfaces to the COM objects in the object model type library. For Outlook, you can use Visual Studio and the Outlook Primary Interop Assembly (PIA). Before you run managed code samples for Outlook 2013, ensure that you have installed the Outlook 2013 PIA and have added a reference to the Microsoft Outlook 15.0 Object Library component in Visual Studio. 您應該使用 Office Developer Tools for Visual Studio) ,在 Outlook 增益集 (類別中使用下列程式碼 ThisAddIn 。 程式碼中的Application物件必須是 所 ThisAddIn.Globals 提供的受信任 Outlook應用程式物件。 如需使用 Outlook PIA 開發受控 Outlook 解決方案的詳細資訊,請參 閱 MSDN 上的歡迎使用 Outlook 主要 Interop 元件參考

下列的 C# 程式碼片段會針對在 [解決方案] 模組中出現的資料夾設定圖示。 程式碼片段相依于 PictureDispConverter 如下所示的 類別。

//Get the icons for the solution 
stdole.StdPicture rootPict = 
 PictureDispConverter.ToIPictureDisp( 
 Properties.Resources.BRIDGE) 
 as stdole.StdPicture; 
stdole.StdPicture calPict = 
 PictureDispConverter.ToIPictureDisp( 
 Properties.Resources.umbrella) 
 as stdole.StdPicture; 
stdole.StdPicture contactsPict = 
 PictureDispConverter.ToIPictureDisp( 
 Properties.Resources.group) 
 as stdole.StdPicture; 
stdole.StdPicture tasksPict = 
 PictureDispConverter.ToIPictureDisp( 
 Properties.Resources.SUN) 
 as stdole.StdPicture; 
 
//Set the icons for solution folders 
solutionRoot.SetCustomIcon(rootPict); 
solutionCalendar.SetCustomIcon(calPict); 
solutionContacts.SetCustomIcon(contactsPict); 
solutionTasks.SetCustomIcon(tasksPict);

以下是 類別的 PictureDispConverter 定義。

using System; 
using System.Drawing; 
using System.Collections.Generic; 
using System.Runtime.InteropServices; 
 
public static class PictureDispConverter 
{ 
 //IPictureDisp GUID. 
 public static Guid iPictureDispGuid = typeof(stdole.IPictureDisp).GUID; 
 
 // Converts an Icon into an IPictureDisp. 
 public static stdole.IPictureDisp ToIPictureDisp(Icon icon) 
 { 
 PICTDESC.Icon pictIcon = new PICTDESC.Icon(icon); 
 return PictureDispConverter.OleCreatePictureIndirect(pictIcon, ref iPictureDispGuid, true); 
 } 
 
 // Converts an image into an IPictureDisp. 
 public static stdole.IPictureDisp ToIPictureDisp(Image image) 
 { 
 Bitmap bitmap = (image is Bitmap) ? (Bitmap)image : new Bitmap(image); 
 PICTDESC.Bitmap pictBit = new PICTDESC.Bitmap(bitmap); 
 return PictureDispConverter.OleCreatePictureIndirect(pictBit, ref iPictureDispGuid, true); 
 } 
 
 
 [DllImport("OleAut32.dll", EntryPoint = "OleCreatePictureIndirect", ExactSpelling = true, 
 PreserveSig = false)] 
 private static extern stdole.IPictureDisp OleCreatePictureIndirect( 
 [MarshalAs(UnmanagedType.AsAny)] object picdesc, ref Guid iid, bool fOwn); 
 
 private readonly static HandleCollector handleCollector = 
 new HandleCollector("Icon handles", 1000); 
 
 // WINFORMS COMMENT: 
 // PICTDESC is a union in native, so we'll just 
 // define different ones for the different types 
 // the "unused" fields are there to make it the right 
 // size, since the struct in native is as big as the biggest 
 // union. 
 private static class PICTDESC 
 { 
 //Picture Types 
 public const short PICTYPE_UNINITIALIZED = -1; 
 public const short PICTYPE_NONE = 0; 
 public const short PICTYPE_BITMAP = 1; 
 public const short PICTYPE_METAFILE = 2; 
 public const short PICTYPE_ICON = 3; 
 public const short PICTYPE_ENHMETAFILE = 4; 
 
 [StructLayout(LayoutKind.Sequential)] 
 public class Icon 
 { 
 internal int cbSizeOfStruct = Marshal.SizeOf(typeof(PICTDESC.Icon)); 
 internal int picType = PICTDESC.PICTYPE_ICON; 
 internal IntPtr hicon = IntPtr.Zero; 
 internal int unused1 = 0; 
 internal int unused2 = 0; 
 
 internal Icon(System.Drawing.Icon icon) 
 { 
 this.hicon = icon.ToBitmap().GetHicon(); 
 } 
 } 
 
 [StructLayout(LayoutKind.Sequential)] 
 public class Bitmap 
 { 
 internal int cbSizeOfStruct = Marshal.SizeOf(typeof(PICTDESC.Bitmap)); 
 internal int picType = PICTDESC.PICTYPE_BITMAP; 
 internal IntPtr hbitmap = IntPtr.Zero; 
 internal IntPtr hpal = IntPtr.Zero; 
 internal int unused = 0; 
 internal Bitmap(System.Drawing.Bitmap bitmap) 
 { 
 this.hbitmap = bitmap.GetHbitmap(); 
 } 
 } 
 } 
} 

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應