views:

31

answers:

2

I have a form which spawns from an excel add-in written with VSTO. I would like the form to remain always above the excel spreadsheet, but still allow the user to interact with the sheet below it.

The forms constructor includes this.TopLevel = true;, but the form still disappears behind the spreadsheet when I select a cell.

Has anyone else come across this problem and found a workaround?

+4  A: 

A form already has TopLevel set to true. You want TopMost.

P/Invoking SetParent() would be best but getting the window handle you need might not be that easy. Maybe Process.GetCurrentProcess().MainWindowHandle

Hans Passant
A: 

if you want to have an interactive form in Excel you'll need to do some pinvoking as Hans said in the original answer. see this link - on MSDN

This example is for the refedit control (which is normally only available from VBA). The example should give you the necessary information on IWin32Window and pinvoking to call the Show method of the form object with this parameter value.

Anonymous Type