문제

배경:나 개발 Outlook2007 에서 추가 VS2010C#.특정한 것은 내가 하는 일은 추가 메뉴 항목의 컨텍스트 메뉴에 관련된 이메일을 보냅니다.내가 이렇게 다음과 같은 코드:

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 변환 기능을 하는 내가 없습니다.거기에 간단한 방법을 설정 또는 비트맵 이미지하십니까?

감사합니다.

도움이 되었습니까?

해결책

하려면 사용자 정의 이미지 당신은에 의존해야 AxHost 방법(보용 다)또는 PictureDispConverter 는 다른 방법 에 의해 만들어 Microsoft 에 따라 OleCreatePictureIndirect.

를 사용하려면에 내장 된 아이콘을 설정할 수 없 FaceId.다운로드 Office 아이콘 갤러리 보 Office2007 FaceId 값이 있습니다.

다른 팁

다음 코드는 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을 리소스에 포함한 이미지를 추가합니다.

just fyi, 여기서 ), getImagemso () 메소드.

CommandBarButton.Picture = Application.CommandBars.GetImageMso("ImageMSO", 16, 16);
.

이것은 FaceID 속성을 사용하는 대안적인 접근 방식입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top