WinForm behaviour in a Office application

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

WinForm behaviour in a Office application
 
Marco Trachsler




Posts: 18
Joined: 2011-12-20
When I click in the adxRibbonbar on the RibbonButton it opens my own WinForm. That works fine. Now I want - for example in a Word document - that when the Word document is minimized that my WinForm is also minimized.

Here is a working code excerpt in a winform:


class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
this.AddOwnedForm(form2);
form2.Show();
}
}



How can I achieve this behaviour in an Office application?
Posted 14 Mar, 2012 05:38:11 Top
Andrei Smolin


Add-in Express team


Posts: 18822
Joined: 2006-05-11
Hello Marco,

Non-modal WinForms usually interfere with the windowing of Office applications. What you see is one of such cases.

I suggest that you find out the state of the Word window using the WindowState property provided by these objects in the Word object model:
- Application
- ProtectedViewWindow
- Task
- Window

Because the Word object model doesn't provide any events related to minimizing/restoring the window, I suggest using the CommandBarsUpdate event of the Word Events component. Be aware, this event occurs really often and you need to optimize your code so that your event handler is processed as fast as possible.

I suppose this task (minimizing/restoring a form) is doable. Nevertheless, check if other apects of your form works correctly: tooltips, keyboard shorcuts, context menus, etc. If any of them works incorrectly, consider using an Advanced Task Pane or Custom Task Panes instead of your form.


Andrei Smolin
Add-in Express Team Leader
Posted 14 Mar, 2012 06:04:10 Top
Marco Trachsler




Posts: 18
Joined: 2011-12-20
Hello Andrei

Thank you for your reply. It works very well with minimized and maximized my WinForm.
I use the adxEvent WindowSize and ask the state of the Word document and customize my WinForm to the Word document state.
Posted 15 Mar, 2012 09:38:48 Top
Andrei Smolin


Add-in Express team


Posts: 18822
Joined: 2006-05-11
Great!


Andrei Smolin
Add-in Express Team Leader
Posted 15 Mar, 2012 09:55:26 Top