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
- A custom button is added to MS office ribbon
- A custom task pane is created after clicking the custom button
- 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
First one is dummy control and the second one contains the sample controls like lable and textbox.
ShowCustomTaskPane function creates a custom task pane with
MyUserControl and adds
Connect" is derived from "
ITaskPane" interface which is used for interaction between Custom Taskpane and
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 (this.Width > 300)
if (m_ObjItaskPane != null)
if (!(sender is ScrollableControl))
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.