Visual C to Visual Basic Converstion Help...

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
 
G

Guest

Our Instant VB C# to VB converter produces the following: (Note that
MessageBox.Show is still fine in VB)

Private Sub AddSubButton(ByVal cb As Office.CommandBarPopup, ByVal
buttonName As String)
Try
Dim missing As Object = Missing.Value
Dim customButton As Office.CommandBarButton
customButton =
CType(cb.Controls.Add(Office.MsoControlType.msoControlButton, missing,
missing, missing, missing), Office.CommandBarButton)
customButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
Dim rm As ResourceManager = New
ResourceManager("CustomFaces.IconResource", Me.GetType().Assembly)
Dim res As System.Drawing.Icon
res = CType(rm.GetObject(buttonName), Icon)
Dim bmp As Bitmap
bmp=res.ToBitmap()
Clipboard.SetDataObject(bmp,True)
customButton.FaceId = 0
customButton.Caption=buttonName
customButton.PasteFace()
Catch exc As Exception
MessageBox.Show(exc.Message,"Adding Sub")
End Try

End Sub

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
G

Guest

The "this" keyword in C# referes to "this" instance of the object

this.GetType() returns the System.Type of the current object.

It is the same as the "Me" keyword in VB.NET.

Me.GetType() returns the System.Type of the current object.
 
Top