More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

forum 23-Apr-2019 02:56

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

    Page [ 1 2 Next >> ]  
 Outlook and .NET Printer Friendly Version
Writing code with C# and VB.NET to create Outlook add-ins and other projects
Topic
Using a .NET WinForms control in an Outlook Form.
I wrote a user control in C#, gave it a GUID and ProgID and registered it for COM Interop (both through Visual Studio and using REGASM).
 When I go to a VBA project and do Add References, I can see my COM project listed there, and I can reference it and instantiate the object successfully.
But when I try to add it to the list of controls under a VBA UserForm or an Outlook Form, I get a different list - the list of possible controls, not type libraries.

What do I have to do to have my control registered in that list and to use it in an Outlook Form?

  04-Aug-2005  09:04
  05-Aug-2005  01:01   
Outlook custom forms and VBA forms can show only ActiveX controls.
  05-Aug-2005  02:09   
HEllo Sue, hello Avner,

i have done some research and, yes it is possible to expose an C# Control as Active-X control so that you can put it on an Outlook Form.
But there is a problem that i must try to fixe before i could post some sample.
The problem is that the position and size properties exposed to COM are different to VB6 Active-X controls and when Outlook tries to update the Control and calls InvalidateRegion...
the parameters passed to the Control are wrong and it gives me an Unhandled exception.
So - i need to do some research again and try to fix it.
When this problem is solved, then it's very easy to create an Active-X control from C# or VB.Net
Sue, do you have good connections directly to the MSFT Programming Team (Outlook/.NET) ? Maybe they can help here ?
The behavior is the same in .Net 2.0 - so maybe it cuold be an enhancement
either for Outlook12 or .Net 2.0

Greets, Helmut Obertanner
[DATALOG Software AG]

  
  05-Aug-2005  03:16   
Hello, Helmut.
I've manage to turn my WinForms control into an ActiveX control using the information here (http://www.codeproject.com/cs/miscctrl/exposingdotnetcontrols.asp). As you've stated, there is a problem with the rendering - the control shows up fine in the form, but the first time I click it (it's a DatePicker, and pops up a calendar) it gives me an Unhandled Exception with an Invalid Rectangle error. Stangely enough, if I press 'continue' and click again, the control DOES work fine, full functionality and everything. But every once in a while it pops up the Invalid Rectangle again.

What do you mean by "the properties exposed to COM are different"? Would this be something that can be worked around by changing the values myself? Is there an offset between them or are the values totally incompatible? Maybe I can add code in my wrapper class that detects the type of host and does the change automatically.
  05-Aug-2005  03:23   
Hello Avner ,

I don't think that we could handle it , it's the way the compiler exposes the Properties as COM. It would be fine that in the future there could be a new "COM Property" "ActiveXCompatibility=true" or similar.
I personal will try to create an MFC Acxtive-X Control, that acts as a wrapper for the managed .Net control.

Greets, Helmut
  05-Aug-2005  04:56   
When you say "the way the compiler exposes the properties as COM", do you mean that it exposes them in a completely incompatible way (passing a pointer rather than a primitive value, or something like that) or that it just passes wrong values? And how did you check it out?
  05-Aug-2005  14:20   
Hello Avner,

i read that while im researching for a solution.
but here is an article that shows some differnces and some common properties are removed.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/actxvnetcontrols.asp

here is another not helpfully article:

http://support.microsoft.com/default.aspx?scid=kb;en-us;311300

and here is an interresting article about showing .Net forms from VB6 and why this gives an error...

http://support.microsoft.com/kb/839076/en-us

We have to do some more research....

greets, Helmut
[DATALOG Software AG]
  09-Aug-2005  02:08   
I've made some progress with it, though it's not really the safest of approaches.
The exception I'm receiving happens in the OnFocus event. I simply overrode the OnGotFocus event in my code and wrapped up the base.OnGotFocus() call with a try/catch. I don't know what else I might be screwing up, but for now it works smoothly.
  09-Aug-2005  02:20   
A few other problems, though:
If I use the control in a VBA Userform, rather than an Outlook form, I get three "Path/File access errors" followed by an "Error 75: could not find the specified object", and then I can't even open the form in the designer.

Second: when I use the control in a form, I can't set its properties - the Properties dialog gives me the default Outlook properties form, and the Advanced Properties just show generic control properties. I can only set the properties through code.
Any way around that?
  09-Aug-2005  03:00   
Update on the first problem:
The .NET control I was exposing was actually an inherited control - I was trying to wrap a 3rd-party .NET control. It seems the problem was due to assembly locations - my wrapper control was in the GAC, but the original 3rd-party control wasn't, so it wasn't found. The runtime looked for it in the GAC, the Office directory and several temp dirs, but no luck.
Once I registered it in the GAC, all went well.
  09-Aug-2005  13:30   
Chris Sells has done the best hack for ActiveX controls that I know of:
http://www.ondotnet.com/pub/a/dotnet/2003/01/20/winformshosting.html

I once tried to get ActiveX controls written in C# (or VB.NET) to work properly in VB6, and I never could. The rabbit hole is very deep indeed. Really, to make it work, the .NET Framework team would have to re-consider what was dropped in the beta1 of the Framework (if my memory serves me right- it was late 1999 or early 2000 when we were still using notepad because there was no VS.NET). There was a built-in feature of the Framework to pump out managed ActiveX controls, but given that the strategy was to move from ActiveX and just focus on the underlying COM and .NET, it was dropped. Funny to look back on now, as ActiveX is still alive and well for so many of our intranet Web apps at MS!
    Page [ 1 2 Next >> ]