VB.net Embed Windows form in a Custom Task Pane


Is it possible to embed  a Windows form in a Custom Task Pane?
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Me.Form2.Parent = MyCustomTaskPane
Jacques Bourgeois (James Burger)PresidentCommented:
Although many thinks the contrary, a Form is actually a Control. You can use a Form anywhere you use a Control (I often use Forms inside of TabControls), that is in any ContainerControl, the same way you would use a Control into it, such as the following. So, if your custom control inherits from ContainerControl or from any control that inherits from ContainerControl, you can to the following:

YourControl.Controls.Add (New yourForm)
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
*For a FORM, you need to set TopLevel() to False before you can add it to a container.  This must be done at run-time.
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. I am not sure where to put the code. I have used the example shown at the following link for my TaskPane. How would I embed Form2 inside this:
Jacques Bourgeois (James Burger)PresidentCommented:
Oh! An Outlook TaskPane. That is something else. You should have told us so. These little details are important when you ask a question.

Outlook is a COM application. It does not use .NET controls, but ActiveX controls that uses other standards.

Microsoft designed Visual Studio .NET to let you write code that can work with ActiveX controls, but you cannot insert .NET controls (a Form is a .NET control as explained before) inside of an ActiveX (Outlook, Word, Excel and many others) application.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Its an Excel TaskPane, I think that article is aimed at Excel and Outlook: "Applies to: The information in this topic applies to application-level projects for the following applications: Excel 2007 and Excel 2010; InfoPath 2007 and InfoPath 2010; Outlook 2007........
Jacques Bourgeois (James Burger)PresidentCommented:
If you go to the article and look at the left pane, you see that it is under the Office UI Customization.

You can use .NET code to manipulate Office, but you cannot use .NET controls for the Office interface because none of the Office applications are .NET, they are all COM applications.

When the article talks about addind controls to the TaskPane, they are from the Office Ribbon Controls, which are not the same type of controls the ones in then Windows.Forms namespace in which the Form is defined.

What you want to do is thus impossible. It like asking to put a Ford motor in a horse. The horse came before the car, so you cannot put a motor inside a horse. You could put a horse inside of a truck however. Same thing here. .NET can work with COM (Office), but not the reverse.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for the clarification. Much appreciated
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
I'm definitely not an Office developer, but following the links it appears to me that you can develop a .Net UserControl that can then be embedded in an Office Custom Task Pane:

Also, see "Custom Task Panes Overview":

    "Windows Forms Support - The user interface of a custom task pane that you create by using the Office development tools in Visual Studio is based on Windows Forms controls. You can use the familiar Windows Forms Designer to design the user interface for a custom task pane. You can also use the data binding support in Windows Forms to bind a data source to controls on the task pane."

    "Creating the User Interface - All custom task panes that are created by using the Office development tools in Visual Studio contain a UserControl object. This user control provides the user interface of your custom task pane. You can create the user control at design time or at run time. If you create the user control at design time, you can use the Windows Forms Designer to construct the user interface of your task pane."

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacques Bourgeois (James Burger)PresidentCommented:
Reading the documentation in the links provided by Idle_Mind seem to point to the fact that I was wrong.

It looks as if they did something special for the CustomTaskPane that did not exist when I did .NET development with Office 2003, where only the TaskPaneControl (not the CustomTaskPane) was available.

I never saw anywhere that you could include a .NET control in a COM application, and I have searched often for that possibility. My hunch is that the CustomTaskPane is not integrated into the Officce application. It might hover over the Office application and "follow" the standard TaskPaneControl through low-level hooks to the Office application, a technique similar to the one that is often used to enhance a grid with a type of cell that it does not provide.

A UserControl is a small Form missing a few features such as the title bar and the control buttons. What you wanted to do with a Form should be possible with a UserControl. And according to Idle_Mind references, this is the way to work with the CustomTaskPane.

You should transfer the points to Idle_Mind if there is a way to do so.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. I have requested that question be reopened. Perhaps some light could be shed on a similar sort of question

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.