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(Of fice.CommandBar Popup cb, string buttonName)
{
try
{
object missing = Missing.Value;
Office.CommandB arButton customButton;
customButton = (Office.Command BarButton) cb.Controls.Add (
Office.MsoContr olType.msoContr olButton,
missing, missing, missing, missing);
customButton.St yle =
Office.MsoButto nStyle.msoButto nIconAndCaption ;
ResourceManager rm = new ResourceManager (
"CustomFaces.Ic onResource", this.GetType(). Assembly);
System.Drawing. Icon res;
res = (Icon) rm.GetObject(bu ttonName);
Bitmap bmp;
bmp=res.ToBitma p();
Clipboard.SetDa taObject(bmp,tr ue);
customButton.Fa ceId = 0;
customButton.Ca ption=buttonNam e;
customButton.Pa steFace();
}
catch (Exception exc)
{
MessageBox.Show (exc.Message,"A dding Sub");
}
}
========
MY Interpretation in VB
========
Function AddSubButton(By Val cb As CommandBarButto n, ByVal buttonname As
String)
Dim missing As Object = missing.Value
Dim customButton As CommandBarButto n
Dim bmp As Bitmap
Dim res As Icon
Dim rm As New ResourceManager ("CustomFaces.I conResource",
rm.GetType().As sembly)
Try
customButton = cb.Controls.Add (MsoControlType .msoControlButt on, _
missing, missing, missing, missing)
customButton.St yle = MsoButtonStyle. msoButtonIconAn dCaption
res = rm.GetObject(bu ttonname)
bmp = res.ToBitmap()
Clipboard.SetDa taObject(bmp, True)
customButton.Fa ceId = 0
customButton.Ca ption = buttonname
customButton.Pa steFace()
Catch
msgbox("Adding Button",MsgBoxS tyle.OKOnly)
End Try
End Function 4 1569
I believe this in C# is equivalent to Me in VB.
Our Instant VB C# to VB converter produces the following: (Note that
MessageBox.Show is still fine in VB)
Private Sub AddSubButton(By Val cb As Office.CommandB arPopup, ByVal
buttonName As String)
Try
Dim missing As Object = Missing.Value
Dim customButton As Office.CommandB arButton
customButton =
CType(cb.Contro ls.Add(Office.M soControlType.m soControlButton , missing,
missing, missing, missing), Office.CommandB arButton)
customButton.St yle = Office.MsoButto nStyle.msoButto nIconAndCaption
Dim rm As ResourceManager = New
ResourceManager ("CustomFaces.I conResource", Me.GetType().As sembly)
Dim res As System.Drawing. Icon
res = CType(rm.GetObj ect(buttonName) , Icon)
Dim bmp As Bitmap
bmp=res.ToBitma p()
Clipboard.SetDa taObject(bmp,Tr ue)
customButton.Fa ceId = 0
customButton.Ca ption=buttonNam e
customButton.Pa steFace()
Catch exc As Exception
MessageBox.Show (exc.Message,"A dding 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
"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(Of fice.CommandBar Popup cb, string buttonName) { try { object missing = Missing.Value; Office.CommandB arButton customButton; customButton = (Office.Command BarButton) cb.Controls.Add ( Office.MsoContr olType.msoContr olButton, missing, missing, missing, missing); customButton.St yle = Office.MsoButto nStyle.msoButto nIconAndCaption ; ResourceManager rm = new ResourceManager ( "CustomFaces.Ic onResource", this.GetType(). Assembly); System.Drawing. Icon res; res = (Icon) rm.GetObject(bu ttonName); Bitmap bmp; bmp=res.ToBitma p(); Clipboard.SetDa taObject(bmp,tr ue); customButton.Fa ceId = 0; customButton.Ca ption=buttonNam e; customButton.Pa steFace(); } catch (Exception exc) { MessageBox.Show (exc.Message,"A dding Sub"); }
}
======== MY Interpretation in VB ======== Function AddSubButton(By Val cb As CommandBarButto n, ByVal buttonname As String)
Dim missing As Object = missing.Value Dim customButton As CommandBarButto n Dim bmp As Bitmap Dim res As Icon Dim rm As New ResourceManager ("CustomFaces.I conResource", rm.GetType().As sembly) Try customButton = cb.Controls.Add (MsoControlType .msoControlButt on, _ missing, missing, missing, missing) customButton.St yle = MsoButtonStyle. msoButtonIconAn dCaption res = rm.GetObject(bu ttonname) bmp = res.ToBitmap() Clipboard.SetDa taObject(bmp, True) customButton.Fa ceId = 0 customButton.Ca ption = buttonname customButton.Pa steFace() Catch msgbox("Adding Button",MsgBoxS tyle.OKOnly) End Try End Function
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(Of fice.CommandBar Popup cb, string buttonName) { try { object missing = Missing.Value; Office.CommandB arButton customButton; customButton = (Office.Command BarButton) cb.Controls.Add ( Office.MsoContr olType.msoContr olButton, missing, missing, missing, missing); customButton.St yle = Office.MsoButto nStyle.msoButto nIconAndCaption ; ResourceManager rm = new ResourceManager ( "CustomFaces.Ic onResource", this.GetType(). Assembly); System.Drawing. Icon res; res = (Icon) rm.GetObject(bu ttonName); Bitmap bmp; bmp=res.ToBitma p(); Clipboard.SetDa taObject(bmp,tr ue); customButton.Fa ceId = 0; customButton.Ca ption=buttonNam e; customButton.Pa steFace(); } catch (Exception exc) { MessageBox.Show (exc.Message,"A dding Sub"); }
}
======== MY Interpretation in VB ======== Function AddSubButton(By Val cb As CommandBarButto n, ByVal buttonname As String)
Dim missing As Object = missing.Value Dim customButton As CommandBarButto n Dim bmp As Bitmap Dim res As Icon Dim rm As New ResourceManager ("CustomFaces.I conResource", rm.GetType().As sembly) Try customButton = cb.Controls.Add (MsoControlType .msoControlButt on, _ missing, missing, missing, missing) customButton.St yle = MsoButtonStyle. msoButtonIconAn dCaption res = rm.GetObject(bu ttonname) bmp = res.ToBitmap() Clipboard.SetDa taObject(bmp, True) customButton.Fa ceId = 0 customButton.Ca ption = buttonname customButton.Pa steFace() Catch msgbox("Adding Button",MsgBoxS tyle.OKOnly) End Try End Function
Thanks all. I've got the conversion all set - I think - now I can't
debug... *sigh* This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: AK |
last post by:
I don't want any part of the previous discussion on Visual Basic
versus Visual Basic.Net.
My query is about using Visual Basic for Applications; and whether it
is better to use Visual Basic 6 or Visual Basic.Net as a springboard
for studying VBA.
I use Office 2000 and would like to use VBA as a tool to customize it.
I have zero...
|
by: Anil Sahai |
last post by:
I installed Visual Studio Version 6.0 with Visual
Basic and Visual C++ etc. When I tried to invoke
Help in Visual BASIC, it said that I should install
MSDN. I installed MSDN using the MSDN library
CDs. Now I can look at the Visual BASIC documentation
(although after several many searches and clicks), I
still cannot invoke "Help" from within...
|
by: janice_2k |
last post by:
Dear Sir/Mdm,
I am writing this on behalf of my company. We bought the Visual Studio .NET Enterprise version but currently we need to use Visual Basic 6 for a small development. We are not able to purchase it anymore, anywhere we know. Therefore, I would like to know whether is VB 6 still available in the market? If not, is there any way we can...
|
by: Ralph |
last post by:
I used to have Visual Basic .net std. 2003 installed on WinXP SP1A. But I
found it too hard to upgrade WinXP to SP2. Now, I do have WinXP SP2
installed, but I am having problems installing Visual Basic .net standard
2003. Not installing Visual Basic at the WinXP SP1A level - was the only way
I found that I could
install WinXPSP2.
My...
|
by: frossberg |
last post by:
Hello!
I tried to install the Visual Basic.NET Resource Kit
(http://msdn.microsoft.com/vbasic/vbrkit/) but obviously something went very
wrong and now it sems impossible both to repair and to remove (to start over
from scratch) the installation. The messages popping up after choosing one of
these two alternatives Repair/Remove Visual...
| |
by: Microsoft |
last post by:
Hi,
I have Visual Basic .net 2003 (Standard Edition) & SQL Server 2000 Developer Edition. When trying to create a connection in the server explorer from the .net IDE I get a number of problems;
a.. Under the "Connection" tab, under "1. Select or enter a server name:" when I either select the drop down box or click the refresh button I get an...
|
by: Master Programmer |
last post by:
An friend insider told me that VB is to be killled off within 18
months. I guess this makes sence now that C# is here. I believe it and
am actualy surprised they ever even included it in VS 2003 in the first
place. Anyone else heard about this development?
The Master
|
by: FlyingBuckner |
last post by:
All right be kind, this is my first question on a forum. I need help on selecting the right software to purchase.
I have a database set up using Access, 6 users. It is split into Tables and Applications, no more then 65MB of data in the tables right now.
I have 2 college courses in Visual Basic 6 and have written VBA code in Access and...
|
by: Salman |
last post by:
I would like to know how I can distribute the application that I
create with Visual C++ express edition. I checked the menu options to
find a deploy option similar to the one found on the Visual Basic
Express Edition but could not find one. I have even searched the help
files and could not find anything useful for me. I want to simply...
|
by: Chris Asaipillai |
last post by:
Hi there
My compay has a number of Visual Basic 6 applications which are front endeed onto
either SQL Server or Microsoft Access databases.
Now we are in process of planning to re-write these applications into Visual Basic.Net.
My managers main thought is that Visual Basic 6 is (or has!) stopped being supported
by Microsoft.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |