0

I have a custom task pane and now I am trying to catch the close event of the custom task pane. I have seen that there is no such event, instead there is the VisibleChanged event with does exactly the same, it is raised when visibility changes or it is closed.

When user clicks on close button or select close from the context menu, I would like to display a messagebox saying it is not permitted to close it and not allow user to close it.

I have seen an approach here or this user a thread but this is causing flickering when showing it again (you can see that it is hidden and then make visible again quickly). Is there any other way to achieve this? Also where is the best place in those approaches to show the messagebox?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Willy
  • 9,848
  • 22
  • 141
  • 284

1 Answers1

1

Custom task panes don't provide any event which is fired when the pane is about to close. There is no trivial way to get the job done, you need to implement workarounds described on forum threads. Also you may consider using Advanced Outlook view and form regions instead.

Note, Outlook form regions provide the following events out of the box:

Event Description
FormRegionInitializing Occurs before the form region is initialized. You can check conditions in this event handler to determine whether Outlook should display the form region. For more information, see How to: Prevent Outlook from displaying a form region.
FormRegionShowing Occurs after an instance of the form region is created but before the form region appears.
FormRegionClosed Occurs before the form region is closed.
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Yep, but you cannot put a form region at the top ;) – Willy Oct 31 '22 at 21:59
  • `Advanced` Forms can be placed, unlike Outlook form regions. – Eugene Astafiev Oct 31 '22 at 22:01
  • But to use advanced forms I need to use Add-in Express third-party tool, right? I don't want to depend on a third-party tool. – Willy Oct 31 '22 at 22:04
  • If you don't want to depend on a third-party components you need to learn Windows API functions and be ready to spend quite a lot of time for implementing workarounds. That is completely your choice! – Eugene Astafiev Oct 31 '22 at 22:18
  • ok, so when you say i will need to learn Windows API functions if i don't want to use third-party tools, then I understand that Add-in Express is using them as well (Windows API functions), right? So it is not only about avoiding dependencies with third-party tools, but also about avoiding the use of hacks and I am afraid that it uses hacks as well. Am I right? – Willy Nov 01 '22 at 09:40
  • 1
    Yep .The world is not ideal, especially around creating MS Office add-ins. – Eugene Astafiev Nov 01 '22 at 21:03