You are here: Office-Outlook.com  / Outlook Forum

Getting .NET form to respond to Excel window events

Home » Outlook addins and plugins development » Developer Outlook add-ins
Getting .NET form to respond to Excel window events [message #163841] Wed, 02 May 2007 05:12 Go to next message
sethnkendall
Messages: 3
Registered: May 2007
Junior Member
Hi,

I am writing a COM add-in for Excel using c#. Everything works fine,
but I am trying to get the some finishing touches sorted out and one
of them is bugging me and I cannot see anything written on the web
trying to achieve this:

My add-in displays a couple of windows forms and some of these behave
more like floating toolbars than standalone modal dialogs. I want to
be able to somehow mirror the behaviour that normal Office commandbars
exhibit (and to some extent modal windows forms) in that:

* when Excel is minimized or deactivated I would like these
"floating" forms to disappear and when Excel is reactivated or
restored to reappear

* when Excel has the focus I would like the form to float over
other windows (if it is not positioned over Excel).

My natural approach is to try to use the api setparent call, but this
does not do what I want. does anyone have any other dieas about how
to do this. ideally, I do not want to hook Excel and respond to
events myself, but would prefer it if their was a natural way I can
"attach" the window to Excel.

Any help is much appreciated.
Seth
RE: Getting .NET form to respond to Excel window events [message #166274] Wed, 02 May 2007 06:25 Go to previous message
XL-Dennis
Messages: 518
Registered: August 2006
Senior Member
Seth,

In VB.NET the following snippet code makes the form to be part of Excel:

Dim frm As New AboutBox1
Dim appWindow As New NativeWindow

Try

appWindow.AssignHandle(Process.GetCurrentProcess().MainWindo wHandle)
frm.ShowDialog(appWindow)
Catch ex As Exception
MessageBox.Show(ex.ToString, My.Application.Info.Title.ToString)
Finally
appWindow.ReleaseHandle()
End Try


Is this what You want?

---------------
With kind regards,
Dennis
Weekly Blog .NET & Excel: http://xldennis.wordpress.com/
My English site: http://www.excelkb.com/default.aspx
My Swedish site: http://www.xldennis.com/
Previous Topic:Getting .NET form to respond to Excel window events
Next Topic:Shared Addin problem
Goto Forum: