This project has moved. For the latest updates, please go here.

Register C# EventHandler with OLE TextBox int PowerPoint presentation

Jan 15, 2015 at 8:57 AM
Edited Jan 15, 2015 at 8:58 AM
I'm launching a PowerPoint presentation from a C# application. This presentation has a special slide, which allows the user to enter values via an OLE TextBox.
Now, I'd like to register an event-handler, for e.g. when the TextBox loses the input focus, or the user presses an "OK"-button.
However, I can't figure out how to register an event-handler with an OLE-Control. Is this Even possible? Is there another way to be notified when the user has entered some values?
Coordinator
Jan 18, 2015 at 4:30 AM
hey man,

please explain OLE Textbox. Means an element from VBA or its an external Active-X control?
(first case is easy but a dialog want shown for the user to agree your access to VBA. The PowerPoint security settings can level this but its not recommended.
second case is more challenging. you need the .net interop wrapper for the control to handle this normaly with += new EventHandler, otherwise you need some special code to do this on demand with COM Connection Containers. May i can help your here if its the scenario )

*Sebastian
Jan 18, 2015 at 10:23 AM
Hey Sebastian,

I added the TextBox via the developer-tools tab. As far as I know these controls a Active-X controls.
Where can I find the .net interop wrapper classes?

Gebhard
Coordinator
Jan 19, 2015 at 10:55 AM
okay then,

This is a normal textbox(no OLE action so far).
Shame on me: I currently figure out how i can reprocuce the scenario, because i can't find the developer tools in PP 2010 with the ugly ribbon ui.
If its possible, please send me an example .pptx to public[at]sebastian.web.de with your magic textbox inside(or explain how i can create a textbox for a document in PP 2010)

*Sebastian
Coordinator
Jan 19, 2015 at 10:56 AM
okay then,

This is a normal textbox(no OLE action so far).
Shame on me: I currently figure out how i can reprocuce the scenario, because i can't find the developer tools in PP 2010 with the ugly ribbon ui.
If its possible, please send me an example .pptx to public[at]sebastian.web.de with your magic textbox inside(or explain how i can create a textbox for a document in PP 2010)

*Sebastian
Jan 19, 2015 at 1:08 PM
here is a link , that describes how you can activate the developer-tools.

I tried to mail my demo-presentation to you, but I got a DNS-error...
Coordinator
Jan 21, 2015 at 3:04 PM
DNS-error..
oops!

[wrong]public[at]sebastian.web.de[/wrong]

[correct]public.sebastian[at}web.de[/correct]

Here is my current research result so far:

The best way to catch the focus events here is to use the current vba code module directly.
You can also use the textbox events in C# with as follows:

1.) add a reference to the COM Component Microsoft Forms 2.0
2.) disable the reference option "embed interop types"

Now use the following sample code:

PowerPoint.Shape sh = slide.Shapes[1]; // we know its a textbox in this sample
object proxy = Invoker.Default.PropertyGet(sh.OLEFormat, "Object");
Microsoft.Vbe.Interop.Forms.TextBox textBox = proxy as Microsoft.Vbe.Interop.Forms.TextBox;

so now you can use the available events for the textBox instance. please keep in your mind:
the textbox instance and all reference there comes from(such event trigger arguments) is not managed from NetOffice.
so you have to free them at hand with Marshal.ReleaseComObject after using.

But i dont why, its impossible to use the following MS Forms 2.0 IControl events.

void Enter(); // Got Focus
void Exit([in] ReturnBoolean* Cancel); // Lost Focus
void BeforeUpdate([in] ReturnBoolean* Cancel);
void AfterUpdate();

I still figure out how its possible to use them.

*Sebastian
Jan 22, 2015 at 6:51 AM
It works, thanks a lot!

I just used your example and hacked a small and dirty demo app.
Since I couldn't find a LostFocus event, I used the Change event and it worked fine.

Thanks for your great help!


Gebhard