RE: Visual C to Visual Basic Converstion Help...
- From: rmacias <rmacias@xxxxxxxxxxxxxxxx>
- Date: Fri, 12 May 2006 05:33:02 -0700
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.
"MRD" wrote:
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
- Follow-Ups:
- References:
- Prev by Date: Re: Vb.Net 2003 Quirks
- Next by Date: Re: Data type conversion question
- Previous by thread: RE: Visual C to Visual Basic Converstion Help...
- Next by thread: Re: Visual C to Visual Basic Converstion Help...
- Index(es):