C# .NET - Сustom button's size in COM addin

Asked By Vadim P
14-Feb-10 11:25 PM

Hi!

I am developing an Excel COM add-in using C#.

What do I have?

 The problem is I can't make buttons with an image of custom size ­­- office automatically scales them to the button's size. So, in Excel 2003 I can change the button’s size, but its face image will be always 16x16 pixels. In Excel 2007 by Ribbon specification I can use two standard buttons (and button image) sizes 16x16 and 32x32 pixels for “normal” and ”large” button size modes.

What do I want to do?

                I want to make a single toolbar in MS Excel. Images of buttons must have a custom size. And if I specify “button_face.png” file as an image for some button then this very button must be scaled to the image’s size, not vice versa. Thus if “button_face.png” image have 64x64 resolution then the button’s size will be 64x64 too. Actually, I just want to find a way to make buttons with a custom(!) size. As you can see I already faced a know size limitations and now trying to find a workaround.

What do I want from you?

                I need your help. Have you any suggestions about ways to circumvent these limitations? I found http://www.toolbartoggle.com/ made to Excel 2007 something like http://img13.imageshack.us/img13/8349/toolbartoggle.png. I’m wondering how they managed this. Their example is showing me there must be a way to solve my problem, no matter how “hooked” this way is.

Sorry for my English and thanks for any help.

Vadim P.

  Adil Saud replied to Vadim P
15-Feb-10 02:53 AM
Hi,

In your Microsoft Excel 2007 Add In, you can always add a user control, you can then load that user control at the statrtup of your Excel 2007 AddIn.

Now on the user control you can add the tool strip/menu strip etc. to get the desired functionality, images, custom buttons, icons, graphically appealing buttons etc, like we do in Windows Forms.
(I have tested the above in VS2008, pls try to use the same).


Hope this will help you, pls let me know if you need any further information on this.

Thanx,
Adil...:))
  Vadim P replied to Adil Saud
16-Feb-10 08:47 PM

Hi Adil Saud.

Looks like you talking about VSTO, but I use VS 2005 without Tools for Office. Is there’s exists any way to make something like described by you without using Tools for Office?

I’ve installed VS2008 with TO and tried your method. I’ve used http://msdn.microsoft.com/en-us/library/microsoft.office.tools.customtaskpane%28VS.80%29.aspx article and created CustomTaskPane with UserControl on it. Is there any other ways to add a panel to Excel?

Custom task pane looks pretty well anyway, thanks for hint. But now I have some http://img688.imageshack.us/img688/4853/captionsize.png with computation pane`s caption height. How can I find it programmatically? I want my toolbar automatically computes its needed height on any machine, so user needn’t adjust it by himself.

Many thanks to you)

Vadim.

  Adil Saud replied to Vadim P
17-Feb-10 02:15 AM
Hi Vadim,

I am talking about VS2008 only ,

1. Open VS2008 IDE...
2. Select File Menu Item
3.. New Menu Item
4. Project Menu Item--> This will open the New Project dialog box.
5. In the New Project dialog box, there are two panes : Project Type and Templates(Also a drop down in the top right corner to select Dot Net Framework.
6. Expand your language selection Visual Basic or Visual C# in the Project Type Pane.
7. Select the Excel 2007 Add In (Or Excel 2003 AddIn ) project template and click on OK.

Now your Excel AddIn project will be opened and you can always add the user control in this project type, so these are some of the initial steps.

Now you can program your user control as per your requirements, you can add the desired controls(Tool strip in your case) just like we do in windows forms.

You can always program the appearance like height, width and other visual properties for the user control. This user control will actually appear as a new Tool Bar or Custom pane in the MS Excel(When you will install it).

You can also program this to have a dynamic width and height.

Hope this will help you, let me know if you need any further information on the same.

Thanx,
Adil...:))
 
(Tool Strip in your case)
La

  Vadim P replied to Adil Saud
17-Feb-10 03:10 AM

Good morning, Adil Saud.

>7. Select the Excel 2007 Add In (Or Excel 2003 AddIn ) project template and click on OK.

As far as I know, this templates is the part of VSTO. Many VS2008 distributives includes Tools for Office. You can check if TO is installed by trying to uninstal VS. In my case this was like this:
1. Uninstall MSVS2008 (Not completely, of course, I just want to open configuration form))
2. Next
3. Add or remove features
4. MSVS - Language Tools - Visual C# - VS Tools for Ofiice is checked.

>Now you can program your user control as per your requirements, you can add the desired controls(Tool strip in your case) just like we do in windows forms.

Yes, but I can`t add toolstrip directly to Excel, do I? I got to create UserControl and then put Toolstrip on it. Then I got to add my UserControl to CustomTaskPane. Am I get you right? Or there is exists any way to add Toolstrip directly to Excel 2007? If you knows such way, please, tell me about it in details.

Grateful for your help.

Vadim.

  Adil Saud replied to Vadim P
18-Feb-10 04:53 AM
Hi Vadim,

You are absolutely right these are VSTO tools in Visual studio 2008, I tried but unfortunately I am not able to find any way that directly adds a tools strip or custom button to AddIn, you need a pane for this.


Thanx,
Adil...:))
  Vadim P replied to Adil Saud
21-Feb-10 05:51 AM
Thanks a lot for your help, Adil Saud! I`m very grateful to you.
Create New Account
help
Excel 2007 to Excel 2003 Excel I am running Excel 2007 with Office but I want to have the feel of Excel 2003. Is this possible? Excel Discussions Microsoft Excel (1) Excel 2007 (1) Excel 2003 (1) Office (1) Toolbar (1) Bliengme
Reset Excel 2003 Excel I have both Excel 2003 & 2007 on my desktop. I want Excel 2003 to open when I open an excel file but 2007 always overrides 2003. How can I reset Excel Miscellaneous Discussions Microsoft Excel
How do i customize font colors in Excel 2003? Excel How do I customize font colors in Excel 2003? Excel Miscellaneous Discussions Microsoft Excel (1) Excel 2003 (1) Workbook (1) Color (1) Global change (1) Font colors (1) Customize
create an upper and lower control limit in Excel 2003? Excel How do I create an upper and lower control limit in Excel 2003? Excel Charting Discussions Microsoft Excel (1) Excel 2003 (1) Charts (1) Bliengme (1) Jon has lots of examples at http
CONVERT function for Excel 2003 Excel I was trying to format time in decimals to days:hours:mins format. While using microsoft excel 2003 help, they said to use CONVERT funtion for the same. But there isnt any CONVERT funtion in the Inset menu> funtions, in excel 2003. I tried for the same on Excel 2003 installed in other computers as well to