Get instance Task pane word

Add-in Express™ Support Service
That's what is more important than anything else

Get instance Task pane word
 
zipi sompo




Posts: 125
Joined: 2013-09-03
Hi,
I use custom task pane in word.(not ADX advanced task panes)
on adxWordEvents_WindowActivate event In the AddinModule class I try to get an instance of my task pane ?Â?Ð?èctlTaskPane?Â?Ð?é
I try to use with adxTaskPane1 from ?Â?Ð?ìAdxtaskPane collection editor?Â?Ð?í. But get null always!
How can I get these instance?
Thanks!
Posted 17 Feb, 2015 04:32:59 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Zipi,

Below is a citation from the manual (see section Custom Task Panes in Office 2007-2013 in the PDF file in the folder {Add-in Express}\Docs on your development PC):


In Add-in Express, you work with the task pane component and task pane instances. The TaskPanes collection of the add-in module contains task pane components of the AddinExpress.MSO.ADXTaskPane type. When you set, say, the height or dock position of the component, these properties apply to every task pane instance that the host application shows. To modify a property of a task pane instance, you should get the instance itself. This can be done through the Item property of the component (in C#, this property is the indexer for the ADXTaskPane class); the property accepts a window object (such as Outlook.Explorer, Outlook.Inspector, Word.Window, etc.) as a parameter and returns an AddinExpress.MSO.ADXTaskPane.ADXCustomTaskPaneInstance representing a task pane instance. For example, the method below finds the currently active instance of the task pane in Outlook 2007 and refreshes it. For the task pane to be refreshed in a consistent manner, this method should be called in appropriate event handlers.


Private Sub RefreshTaskPaneInOutlookWindow(ByVal ExplorerOrInspector As Object)
   If Me.HostMajorVersion >= 12 Then
      Dim TaskPaneInstance As _
         AddinExpress.MSO.ADXTaskPane.ADXCustomTaskPaneInstance = _
            AdxTaskPane1.Item(ExplorerOrInspector)
      If Not TaskPaneInstance Is Nothing And TaskPaneInstance.Visible Then
         Dim uc As UserControl1 = TaskPaneInstance.Control
         If Not uc Is Nothing Then _
           uc.InfoString = GetSubject(ExplorerOrInspector)
      End If
   End If
End Sub


Does this help?


Andrei Smolin
Add-in Express Team Leader
Posted 17 Feb, 2015 06:12:29 Top
zipi sompo




Posts: 125
Joined: 2013-09-03
I try to translate it to c# to my word task pane.
as
var TaskPaneInstance = adxTaskPane1.Item(ExplorerOrInspector) as AddinExpress.MSO.ADXTaskPane.ADXCustomTaskPaneInstance;
but there is no property Item to adxTaskPane1..

what I try to do is to get my task pane instance from AddinModule class.
Posted 17 Feb, 2015 07:13:35 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Use an indexer instead: adxTaskPane1[ExplorerOrInspector].


Andrei Smolin
Add-in Express Team Leader
Posted 17 Feb, 2015 07:32:50 Top
zipi sompo




Posts: 125
Joined: 2013-09-03
I pass it from adxWordEvents_WindowActivate event to AddinModule_OnTaskPaneBeforeShow event like:
private void AddinModule_OnTaskPaneBeforeShow(object sender, ADXTaskPaneShowEventArgs e)
{
ctlTaskPane taskpane = CurrentInstance.adxTaskPane1[this.WordApp.ActiveWindow].Control as ctlTaskPane;
}
and it works.
Thanks!
Posted 17 Feb, 2015 08:08:44 Top
zipi sompo




Posts: 125
Joined: 2013-09-03
but I have anpther problem when i try to unvisible its does not work:
private void AddinModule_OnTaskPaneBeforeShow(object sender, ADXTaskPaneShowEventArgs e)
{
ctlTaskPane taskpane = CurrentInstance.adxTaskPane1[this.WordApp.ActiveWindow].Control as ctlTaskPane;
taskpane.Visible = false;
}
always show the task pane.
Posted 17 Feb, 2015 08:12:20 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Try hiding adxTaskPane1[this.WordApp.ActiveWindow].

and pay attention: there may be no active window in Word.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Feb, 2015 08:19:13 Top
zipi sompo




Posts: 125
Joined: 2013-09-03
Hi Andrei,
Sometimes I need to not show the pane (I use user control task pane, not the advance one)
In ?Â?Ð?ìAdxtaskPane collection editor?Â?Ð?í I put visible:true to my task pane.
Then I tried to do it on OnTaskPaneBeforeShow event of the addinModule in different ways:

adxTaskPane1[this.WordApp.ActiveWindow].Visible = false;


(sender as AddinExpress.MSO.ADXTaskPane).Visible = false;


taskpane.Visible = false;

Still no success. The pane always visible.
Thanks
Posted 18 Feb, 2015 03:38:31 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Zipi,

The code lines below hide the form at startup and switch the form's visibility when clicking a ribbon button:

private void AddinModule_OnTaskPaneBeforeShow(object sender, ADXTaskPaneShowEventArgs e) {
    e.Cancel = true;
}

private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed) {
    object window = null;
    try {
        window = this.WordApp.ActiveWindow;
    } catch (Exception ex) {
    }
    if (window != null) {
        adxTaskPane1[window].Visible = !adxTaskPane1[window].Visible;
        Marshal.ReleaseComObject(window); window = null;
    }
}



Andrei Smolin
Add-in Express Team Leader
Posted 18 Feb, 2015 10:12:27 Top
zipi sompo




Posts: 125
Joined: 2013-09-03
It's works!
Thanks a lot!!
Posted 19 Feb, 2015 02:13:09 Top