M
MRD
Hi All, I found a useful bit of code on msdn in VC but need it in VB.
I've started the conversion but can't quite finish. The code puts a
custom Icon on a toolbar (In my case the Word Add-in "Standard" bar.
I don't know how to handle the "resource manager" line especially the
"this.GetType()". What the heck is "This?" (and don't start the "who's
on first routine please
Also, what is the reference for clipboard objects?
Also, I'm applying the tool to a command bar button, not a menu pop-up
but I'm assuming the code is analogous and I only have to switch types.
Thanks in advance,
Mark
=========
The original code
=========
private void AddSubButton(Office.CommandBarPopup cb, string buttonName)
{
try
{
object missing = Missing.Value;
Office.CommandBarButton customButton;
customButton = (Office.CommandBarButton) cb.Controls.Add(
Office.MsoControlType.msoControlButton,
missing, missing, missing, missing);
customButton.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption;
ResourceManager rm = new ResourceManager(
"CustomFaces.IconResource", this.GetType().Assembly);
System.Drawing.Icon res;
res = (Icon) rm.GetObject(buttonName);
Bitmap bmp;
bmp=res.ToBitmap();
Clipboard.SetDataObject(bmp,true);
customButton.FaceId = 0;
customButton.Caption=buttonName;
customButton.PasteFace();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message,"Adding Sub");
}
}
========
MY Interpretation in VB
========
Function AddSubButton(ByVal cb As CommandBarButton, ByVal buttonname As
String)
Dim missing As Object = missing.Value
Dim customButton As CommandBarButton
Dim bmp As Bitmap
Dim res As Icon
Dim rm As New ResourceManager("CustomFaces.IconResource",
rm.GetType().Assembly)
Try
customButton = cb.Controls.Add(MsoControlType.msoControlButton, _
missing, missing, missing, missing)
customButton.Style = MsoButtonStyle.msoButtonIconAndCaption
res = rm.GetObject(buttonname)
bmp = res.ToBitmap()
Clipboard.SetDataObject(bmp, True)
customButton.FaceId = 0
customButton.Caption = buttonname
customButton.PasteFace()
Catch
msgbox("Adding Button",MsgBoxStyle.OKOnly)
End Try
End Function
I've started the conversion but can't quite finish. The code puts a
custom Icon on a toolbar (In my case the Word Add-in "Standard" bar.
I don't know how to handle the "resource manager" line especially the
"this.GetType()". What the heck is "This?" (and don't start the "who's
on first routine please

Also, what is the reference for clipboard objects?
Also, I'm applying the tool to a command bar button, not a menu pop-up
but I'm assuming the code is analogous and I only have to switch types.
Thanks in advance,
Mark
=========
The original code
=========
private void AddSubButton(Office.CommandBarPopup cb, string buttonName)
{
try
{
object missing = Missing.Value;
Office.CommandBarButton customButton;
customButton = (Office.CommandBarButton) cb.Controls.Add(
Office.MsoControlType.msoControlButton,
missing, missing, missing, missing);
customButton.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption;
ResourceManager rm = new ResourceManager(
"CustomFaces.IconResource", this.GetType().Assembly);
System.Drawing.Icon res;
res = (Icon) rm.GetObject(buttonName);
Bitmap bmp;
bmp=res.ToBitmap();
Clipboard.SetDataObject(bmp,true);
customButton.FaceId = 0;
customButton.Caption=buttonName;
customButton.PasteFace();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message,"Adding Sub");
}
}
========
MY Interpretation in VB
========
Function AddSubButton(ByVal cb As CommandBarButton, ByVal buttonname As
String)
Dim missing As Object = missing.Value
Dim customButton As CommandBarButton
Dim bmp As Bitmap
Dim res As Icon
Dim rm As New ResourceManager("CustomFaces.IconResource",
rm.GetType().Assembly)
Try
customButton = cb.Controls.Add(MsoControlType.msoControlButton, _
missing, missing, missing, missing)
customButton.Style = MsoButtonStyle.msoButtonIconAndCaption
res = rm.GetObject(buttonname)
bmp = res.ToBitmap()
Clipboard.SetDataObject(bmp, True)
customButton.FaceId = 0
customButton.Caption = buttonname
customButton.PasteFace()
Catch
msgbox("Adding Button",MsgBoxStyle.OKOnly)
End Try
End Function