الوظيفة الإضافية لبرنامج Outlook 2007:كيفية إضافة رمز إلى msoControlButton
-
14-12-2019 - |
سؤال
خلفية:أقوم بتطوير وظيفة إضافية لبرنامج Outlook 2007 في VS2010 في C#.الشيء المحدد الذي أفعله هو إضافة عنصر قائمة إلى قائمة السياق المرتبطة بالبريد الإلكتروني.أفعل هذا بالكود التالي:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.ItemContextMenuDisplay += Application_ItemContextMenuDisplay;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void Application_ItemContextMenuDisplay(Office.CommandBar commandBar, Outlook.Selection selection)
{
var cmdButtonCallContact = (Office.CommandBarButton)commandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, System.Reflection.Missing.Value, 6, System.Reflection.Missing.Value);
cmdButtonCallContact.Caption = "&Foo";
//cmdButtonCallContact.Picture = ?
cmdButtonCallContact.Click += cmdButtonCopy_Click;
}
private void cmdButtonCopy_Click(Office.CommandBarButton ctrl, ref bool canceldefault)
{
System.Windows.Forms.MessageBox.Show("Bar");
}
مشكلة:يبدو أنه لا يمكن ضبط الصورة.تعتمد أمثلة Msdn على وظائف تحويل AxHost التي لا أملكها.هل هناك طريقة مباشرة لتعيين صورة أو BitMap على صورة؟
شكرًا.
المحلول
إذا كنت تريد صورة مخصصة عليك الاعتماد عليها AxHost
يقترب (راجع مرجع MSDN) أو PictureDispConverter
وهو نهج آخر تم إنشاؤها بواسطة مايكروسوفت مرتكز على OleCreatePictureIndirect
.
إذا كنت ترغب في استخدام الرموز المضمنة، يمكنك فقط تعيين FaceId
.تحميل معرض أيقونات المكتب لعرض اوفيس 2007 FaceId
قيم.
نصائح أخرى
يستخدم الكود التالي a System.Drawing.Bitmap
(المخزن كمورد) ويحوله إلى صورة يمكن تخصيصها لها Office.CommandBarButton.Picture
private Office.CommandBarButton buttonOne;
void createbutton()
{
Office.CommandBar newMenuBar = Inspector.CommandBars.Add("EAD", Office.MsoBarPosition.msoBarTop, false, true);
buttonOne = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true);buttonOne.Caption = "Ansari";
buttonOne.Style = Office.MsoButtonStyle.msoButtonIconAndWrapCaptionBelow;
buttonOne.Picture = getImage();
//Register send event handler
buttonOne.Click += buttonOne_Click;
newMenuBar.Visible = true;
}
void buttonOne_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
{
MessageBox.Show("Hi");
}
private stdole.IPictureDisp getImage()
{
stdole.IPictureDisp tempImage = null;
try
{
System.Drawing.Bitmap newIcon = Properties.Resources.Icon1;
System.Windows.Forms.ImageList newImageList = new System.Windows.Forms.ImageList();
newImageList.Images.Add(newIcon);
tempImage = ConvertImage.Convert(newImageList.Images[0]);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
return tempImage;
}
sealed public class ConvertImage : System.Windows.Forms.AxHost
{
private ConvertImage() : base(null)
{
}
public static stdole.IPictureDisp Convert(System.Drawing.Image image)
{
return (stdole.IPictureDisp)System.Windows.Forms.AxHost.GetIPictureDispFromPicture(image);
}
}
ملحوظة:أضف صورة بالاسم Icon1 في المورد.
فقط لمعلوماتك، إذا كنت تريد تطبيق أي صور مدمجة في المكتب على الزر الخاص بك (اطلع على معرض الصور في هنا)، يمكنك ببساطة الاتصال جيتماجيمسو () طريقة.
CommandBarButton.Picture = Application.CommandBars.GetImageMso("ImageMSO", 16, 16);
هذا هو نهج بديل للاستخدام FaceID
ملكية.