Click here to Skip to main content
12,943,528 members (52,996 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 20 Aug 2013

Resize your custom task panes in MS Office applications

, 20 Aug 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
This article briefly explains about resizing of custom task panes in Execl/Word/powerpoint


There is no resize event for custom task panes in Excel/Word/PowerPoint. If you want to resize your custom task panes using COM addin in C# when the parent application (Excel/Word/PowerPoint) is resized i.e., maximized, minimized or windows resolution changed, you are at the correct place.


The basics for creating COM addins in C# for MS Office applications is already available in CodeProject itself. So I assume that the following prerequisites are met,

  1. A custom button is added to MS office ribbon
  2. A custom task pane is created after clicking the custom button
  3. Taskpane contains a user control which has the necessary controls as per your requirement. 

Using the code

I have attached a sample MSI and source code for this sample. This example contains two user controls named MyUserControl and MyUserControl2. First one is dummy control and the second one contains the sample controls like lable and textbox.

The ShowCustomTaskPane function creates a custom task pane with MyUserControl and adds MyUserControl2 dynamically. The "Connect" is derived from "ITaskPane" interface which is used for interaction between Custom Taskpane and MyUserControl2.

When MyUserControl2 loads, its controls' sizes are adjusted according to the TaskPane size. MyUserControl2 constructor stores the current resolution. When the Office application is resized, MyUserControl2_Resize function is called. This function is responsible for adjusting the controls size based on resolution and scroll bar visibility.

private void MyUserControl2_Resize(object sender, EventArgs e)
    if (m_IsCtrlLoading)

    if (this.Width > 300)
        //Dont allow the width of the task pane to be modified. 
        if (m_ObjItaskPane != null)
            m_ObjItaskPane.SetTaskPaneDim(300, 0);

    if (!(sender is ScrollableControl))

    // If Scroll bar exists, dont adjust the size of controls.
    // If resolution changed, you must adjust the controls 
    ScrollableControl scrllCtrl = sender as ScrollableControl;
    if (IsResolutionChanged() || scrllCtrl.VerticalScroll.Visible == false)

If scrollbar in taskbar is visible, we no need to adjust the controls. If resolution is changed, adjusting the controls' size become mandatory. The width of the TaskPane is kept constant because horizontal scroll bar will take care of the control's visibility in TaskPane. 


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


About the Author

Software Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Amir Mohammad Nasrollahi20-Aug-13 6:20
professionalAmir Mohammad Nasrollahi20-Aug-13 6:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170518.1 | Last Updated 20 Aug 2013
Article Copyright 2013 by Sivaji1565
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid