Esempio n. 1
0
        AddButton(
            Office.CommandBarButton cbb,
            Office.CommandBar cbar,
            string name,
            Assembly asmbly,
            string bitMapName,
            string caption,
            string description,
            string toolTipText,
            Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler eventHandler)
        {
            object missing = System.Reflection.Missing.Value;

            try
            {
                cbb = (Office.CommandBarButton)cbar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);

                cbb.Style           = Office.MsoButtonStyle.msoButtonIconAndCaption;
                cbb.Caption         = caption;
                cbb.DescriptionText = description;
                cbb.Picture         = ConvertImage.GetPicture(asmbly, bitMapName);
                cbb.TooltipText     = toolTipText;
                cbb.Tag             = Common.TAG_PREFIX + name;
                cbb.Click          += eventHandler;
                return(cbb);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                // TODO: Add Logging
                throw ex;
            }
        }
Esempio n. 2
0
        GetPicture(Assembly asmbly, string bitMapName)
        {
            Stream     imgStream;
            PictureBox pb             = new PictureBox();
            string     fullBitmapName = asmbly.GetName().Name + "." + bitMapName;

            try
            {
                imgStream          = asmbly.GetManifestResourceStream(fullBitmapName);
                pb.BackgroundImage = Image.FromStream(imgStream);
                imgStream.Close();
                return(ConvertImage.ImageToIPicture(pb.BackgroundImage));
            }
            catch (Exception ex)
            {
                MessageBox.Show("Missing bitmap? " + fullBitmapName + ":" + ex.ToString());
                imgStream          = Assembly.GetExecutingAssembly().GetManifestResourceStream("AddinHelper.missing.bmp");
                pb.BackgroundImage = Image.FromStream(imgStream);
                imgStream.Close();
                return(ConvertImage.ImageToIPicture(pb.BackgroundImage));
            }

            #region old ideas

            //Stream imgStream = null;
            //Dim imgList As New ImageList   ' Uncomment if using below
            //PictureBox pb = new PictureBox();
            //Dim dataO As New DataObject    ' Uncomment if using below

            //try
            //{
            //imgStream = asmbly.GetManifestResourceStream(BitMap);
            // Use this if multiple images
            //imgList.Images.Add(Image.FromStream(imgStream))
            // Use this if one image
            //pb.BackgroundImage = Image.FromStream(imgStream);
            //imgStream.Close();

            //tempAddButtonWithIcon.Style = Office.MsoButtonStyle.msoButtonIcon;
            //tempAddButtonWithIcon.DescriptionText = DescriptionText;

            // bit map to button options.
            // ToDo: Pick one of these two techniques.  Both are flawed in using the
            // clipboard as something important may be overwritten.

            // 1
            //dataO.SetData(System.Windows.Forms.DataFormats.Bitmap, imgList.Images.Item(0))
            //Clipboard.SetDataObject(dataO)
            //.PasteFace()

            // 2
            //Clipboard.SetDataObject(pb.BackgroundImage)
            //.PasteFace()

            // 3 good - no clipboard usage - useful when need list of images.
            //.Picture = ConvertImage.ImageToIPicture(imgList.Images.Item(0))


            // 4 good - no clipboard usage
            //tempAddButtonWithIcon.Picture = ConvertImage.ImageToIPicture(pb.BackgroundImage);

            // End bit map to button options
            //}
            #endregion
        }