Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
Hi,

I wrote a extension for VS2010 some time ago. After learning that it may have still use, published it, even I'm not fully satisfied with it's look.

I'm talking about a toolbar that has button for every web browser installed on your machine. You can push the button and next time your web application will run in the selected browser.

I have two questions...

The buttons created dynamically like this:
C#
private void BeforeQueryStatus ( object sender, EventArgs e )
{
    OleMenuCommand oOleMenuCommand = ( OleMenuCommand )sender;

    if ( oOleMenuCommand != null )
    {
        int nIndex = oOleMenuCommand.CommandID.ID - ( int )Consts.BrowsersListButton;

        oOleMenuCommand.Checked = nIndex == _Current;

        oOleMenuCommand.Text = ( ( BrowserCaps )_Browsers[ nIndex ] ).DisplayName;
    }
}

Where _Browsers is a list of the browsers found on your machine...

My problem is that I prefer to display images and not names, but found no way to add image to the button, dynamically, from external source...

The other problem is connected to the customization of toolbar. Like VS built-in toolbars, my one also subject to custom re-design. I do not want this. In the vsct file I declared the toolbar and the button with no-customize option:

XML
<Menu guid="CMD_SET" id="BrowsersListToolbar" type="Toolbar" priority="0">
    <Parent guid="CMD_SET" id="BrowsersListToolbar" />
    <CommandFlag>NoCustomize</CommandFlag>
    <Strings>
        <ButtonText>Web Browser Selector</ButtonText>
    </Strings>
</Menu>


XML
<Button guid="CMD_SET" id="BrowsersListButton" type="Button" priority="0">
    <Parent guid="CMD_SET" id="BrowsersListGroup" />
    <CommandFlag>DynamicItemStart</CommandFlag>
    <CommandFlag>TextChanges</CommandFlag>
    <CommandFlag>IconAndText</CommandFlag>
    <CommandFlag>NoButtonCustomize</CommandFlag>
    <Strings>
        <ButtonText>[Browsers List]</ButtonText>
    </Strings>
</Button>

This seems do nothing...

There are some suggestions?

Thanks
Peter
Posted
Updated 20-Nov-13 1:24am
v4

1 solution

Take a look at my article, Numbered Bookmarks - Visual Studio Extension VSX 2010[^]. It covers using Images for Menu items and some of that can be helpful.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 20-Nov-13 7:23am    
The problem is that I want to add that image from a external source - the icon of the specific browser. I will improve the question to make it clear.
(I do know the way you used in your project and I ill up-vote your answer, because you made an effort and your article is a good one, but can't accept it as an answer...)
The Manoj Kumar 20-Nov-13 13:10pm    
Sure, accepting as answer is not an issue :).

In your case I can suggest to:
1. Extract Icon from the exe while initializing or loading your adding
2. Save the image to your resources.resx with a variable name pointing to the name of the resource
3. Add the commands at run time

Some articles that can help you in this will be:
1. http://einaregilsson.com/easy-way-to-have-custom-icons-in-visual-studio-addin/
2. http://msdn.microsoft.com/en-us/library/gg418542%28v=vs.110%29.aspx
3. http://stackoverflow.com/questions/462270/get-file-icon-used-by-shell

I cannot think of anything else at this point.
Kornfeld Eliyahu Peter 1-Dec-13 4:58am    
I think that in this case my problem that I want to be more-than-perfect, in that way, that I do not want to store any images in any kind of resource files. What I'm saying is that, there is already a resource for the image I want to assign to my toolbar, so why not load it...
(I done it in one of my old projects using WIN32 API)
In any way I went through the samples, and they are good, but not for me.
To be sure I'm very appreciate your efforts...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900