473,614 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding Visual Studio's ToolBox item by code

Hello,
I'm writing C# code and executing it using InstallUtilLib. dll from custom
action during an installation process. It works fine.

I've written some code to add an item (component) to Visual Studio .NET 2003
toolbox and I've got some serious problems with it.

Problem looks like this:
1) My code works if Visual Studio is already opened when my code executes.
2) My code works fine when executed outside of an installation project.
3) If my code is executed from an installation project and Visual Studio is
not opened, then ToolBox item is not added. I've added a "MessageBox " during
the process and I can confirm that devenv.exe *is* executed.

Here is a function used to get access to Visual Studio's process:

bool OpenVisualStudi oHandle(out EnvDTE.DTE dteObject)
{
// sprobuj uzyskac dostep do wczesniej otwartego okna Visual Studio .NET 2003
try
{
dteObject = (EnvDTE.DTE)
System.Runtime. InteropServices .Marshal.GetAct iveObject("Visu alStudio.DTE.7. 1");
}
catch
{
dteObject = null;
}
if (dteObject != null) return false;
// nie ma otwartego okna z Visual Studiem - otworz nowe
dteObject = (EnvDTE.DTE)
Microsoft.Visua lBasic.Interact ion.CreateObjec t("VisualStudio .DTE.7.1", "");
return true;
}


And here is the code:

void CreateComponent InVisualStudioT oolBox()
{
EnvDTE.DTE dteObject;
bool dteObjectCreate d = OpenVisualStudi oHandle(out dteObject);
if (dteObject == null) return;
try
{
EnvDTE.Window ToolBoxWnd =
dteObject.Windo ws.Item(EnvDTE. Constants.vsWin dowKindToolbox) ;
EnvDTE.ToolBoxT ab tlbTab = GetToolBoxTabBy Name(ToolBoxWnd , "Components ");
if (tlbTab != null)
{
// pokaz okno ToolBox (mozna dokonywac zmian tylko, jesli okno jest
widoczne)
ToolBoxWnd.Visi ble = true;
// wybierz zakladke "Components "
tlbTab.Activate ();
EnvDTE.ToolBoxI tems tlbItems = tlbTab.ToolBoxI tems;
// dopisz siebie do toolboxa
string DllFullPath =
System.Reflecti on.Assembly.Get ExecutingAssemb ly().Location;
tlbItems.Add("C odeCityReaderPo rt", DllFullPath,
EnvDTE.vsToolBo xItemFormat.vsT oolBoxItemForma tDotNETComponen t);
}
}
finally
{
// zamknij Visual Studio, jesli na poczatku je otworzyles
if (dteObjectCreat ed)
{
dteObject.Quit( );
}
}
}
--
SÅ‚awomir Piotrowski / Telsat GP
Rejestracja Czasu Pracy i Kontrola Dostępu
http://www.ewidencja-czasu-pracy.pl

Nov 1 '05 #1
5 2444
Hi,
Welcome to MSDN Newsgroup!

Based on the current situation, please help me to confirm some information
on your side:
1.What about your program, VS.NET Add-In or something else?

2. >>" My code works fine when executed outside of an installation project."
In this scenario, whether or not the VS2003 IDE is opened? If not, I want
to confirm how you run this code.

If you have any questions or concerns, please feel free to let me know.
I'm looing forward to you. :)

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 2 '05 #2
> Hi,
Welcome to MSDN Newsgroup!
Thank you for the reply, answers inline.
Based on the current situation, please help me to confirm some information
on your side:
1.What about your program, VS.NET Add-In or something else?
My program (in fact it's a class library) is a .NET component. It can be
used with or without visual designer. I want to add it to Visual Studio's
component tab in the ToolBox.
2. >>" My code works fine when executed outside of an installation project."
In this scenario, whether or not the VS2003 IDE is opened?
Well... I thought I've checked both ways, but now it looks like it works
only if Visual Studio .NET is opened when my code is executed.
If not, I want to confirm how you run this code.


In order to launch separately I compile it as a console application, define
Main function that creates an "Installer" object and directly executes
CreateComponent InVisualStudioT oolBox.

In case it matters - I'm testing the code under Polish version of Windows XP
Pro with Service Pack 2 and all current patches installed. I'm using an
account with local admin privs.

--
SÅ‚awomir Piotrowski / Telsat GP
Rejestracja Czasu Pracy i Kontrola Dostępu
http://www.ewidencja-czasu-pracy.pl

Nov 4 '05 #3
Hi,

Based on your code, it will add items to an existed VS .Net Instance, so
it's necessary to make VS .NET opened for the code working. (This behavior
is as expected.)
If we want to add the items to the VS.NET 2003 IDE persistently after
installing once, the general convention is using a VS.NET add-in to achieve
the goal.

I browse some articles and hope it's helpful for you.
Title: Visual Studio .NET 2003 Automation Samples (including some add-in
samples)
URL:http://www.microsoft.com/downloads/d...FF9C915-30E5-4
30E-95B3-621DCCD25150&di splaylang=en

Title: Deploying Controls to VS.NET Toolbox Programatically
URL: http://www.codeproject.com/dotnet/AddItemToToolBar.asp
If you have any questions or concerns, please feel free to let me know.
Thanks for your understanding.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 8 '05 #4
Hello,
I've changed my code to follow code from codeproject and it works fine now.
Thanks, Terry Fei.
--
SÅ‚awomir Piotrowski / Telsat GP
Rejestracja Czasu Pracy i Kontrola Dostępu
http://www.ewidencja-czasu-pracy.pl

Nov 9 '05 #5
Hi Slawomir,

I am glad to know that the problem is resolved now. It's really been a
pleasure working
with you.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 9 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1974
by: Brett | last post by:
For some reason in my project, I am unable to add a new web user control in Visual Studio. Normally I would right somewhere in my web app and "Add Web User Control", but when I do this it creates an ASPX page. If I try to then "Add new item" the web user control is not specified in the list. It has worked fine in the past. Any ideas? Cheers,
1
1673
by: Dale | last post by:
When I want to add item to toolbox, the IDE will hang. I don't know why. I checked the Event Log, I found two error messages. 1. Detection of product '{E05F0409-0E9A-48A1-AC04-E35E3033604A}', feature 'VB_for_VS_7_Ent' failed during request for component '{CB5D1205-CCE7-4D3E-99DB-37AB00740D97}' 2. Detection of product '{E05F0409-0E9A-48A1-AC04-E35E3033604A}', feature
1
5793
by: Javier Ros | last post by:
Hi guys!, I´m tring to install my own component in the Visual Studio .Net ToolBox, I have tried with this code: // Create a EnvDTE object. System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.7.1"); object obj = System.Activator.CreateInstance(t, true); EnvDTE.DTE env = (EnvDTE.DTE)obj; // Find the ToolBox Window and ToolBox Tabs collection
3
4868
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
5
397
by: Slawomir Piotrowski | last post by:
Hello, I'm writing C# code and executing it using InstallUtilLib.dll from custom action during an installation process. It works fine. I've written some code to add an item (component) to Visual Studio .NET 2003 toolbox and I've got some serious problems with it. Problem looks like this:
4
2725
by: Nadav Popplewell | last post by:
Hi everybody, I've install Visual studio Team Edition for Testers on my computers, And I can't seem to find how to show the toolbox. The documenation says there should be a 'Toolbox' menuitem under 'view' menu, But I don't have it! This happens both when editing WinForms & WebForms. Thanks, Nadav
3
2361
by: Tin Gherdanarra | last post by:
A colleague gave me a project where there was a /designer/ window for database connectivity (drag&drop from the toolbox), but I can't find out how to get a /designer/ window in my own project. Shift-F7 does not work. What do I have to do in order to get a /designer/ window? Thanks Tin
1
2393
by: Jedufa | last post by:
following of thread: "Adding namespaces to code behind automatically" Hello, I had quite the same problem and got further in the right direction with your suggestions, thanks. Nevertheless, I have a newer problem which seems to come from the fact that the assembly which contains my "SimpleComponentToolboxItem" must be already referenced
4
1801
by: Steve B. | last post by:
Hi As we ship some controls with one of our application that targets web designers, we want to add items in the toolbox of the two products. With VS 2005, it is quite easy, but what about this two products ? We was able to add our controls in the standards group, by modifying the standard.xml file located in Program Files\Office12\1033, but this looks like much a trick than a supported operation.
0
8198
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7115
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5549
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1438
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.