MAKING .NET CONTROLS - OCX VB6 COMPLIANT
Hi all,
I have to create a .NET control. It have to run in a vb6 app.
I'd like to use it like a standard OCX control. I've found in the net that it's possible.
there's anyone who can tell me in which way I can do it?
It's simple:
have a .net control and import it in a VB6 controls list by "add control". and have it working right.
Dario
TIA for any suggestion!
Turns out this is relatively easy to do, although not as easy as we'd like and there is currently an annoying Windows Form bug which makes it more difficult than necessary to hook up events in VB6.
The good news is that we're going to release some examples/code on this very topic in the next few months and the bug I mentioned will be fixed in a service pack later on. Check back to this forum later!
Toddap_MS
Dear Toddap,
Please let me know on the progress of the examples and bug fix below.
In particular does anyone have experience of using .net controls as activex ocx's to be loaded by
the software product 'WonderWare Intouch View' this is a SCADA system for viewing industial control data.
this product is able to load activex ocx's created from Microsoft VB6.
Toddap_MS wrote: |
| Turns out this is relatively easy to do, although not as easy as we'd like and there is currently an annoying Windows Form bug which makes it more difficult than necessary to hook up events in VB6. The good news is that we're going to release some examples/code on this very topic in the next few months and the bug I mentioned will be fixed in a service pack later on. Check back to this forum later! Toddap_MS |
|
Dear Toddap, does anyone have any simple to
follow articles about exposing a .NET class as non-ocx
activex control, the class needs methods plus an event
to be called when an asynchronus task is complete.
again this is actually to be used in the script of the
software product 'wonderware intouch view' also
known as 'wonderware factorysuite windowviewer'
best wishes nick.
Jon's link above contains a start. Again, we hope to have something significantly easier for people to use. You should see something shortly from us in early November.
Toddap_MS
Hi Toddap_MS,
I tried that sample code (i.e. compiled it etc.) on one PC but now want
to try it now on another PC. I can't register it as you would a VB6
control. However it's obviously not as simple as just copying the dll
over either. What's the best way of porting this these .Net controls
around?
Thanks for your help.
crafman
So, this will be better doc'd in the upcoming release, but here's a brief summary:
1) If you are deploying a VB6 app using this control, just copy the control to where your vb6 exe is located, run regasm.exe on it (which is a utility in your frameworks directory) on the control, and then your app should run fine.
2) If you want to install the usercontrol "globally" like a VB6 .ocx or you want to use the usercontrol from VB6.exe, just copy the control locally and run this:
regasm.exe <mycontrol.dll> /codebase /tlb:mycontrol.tlb
Then it should work.
Toddap_MS
Hi!
I was able to make a usercontrol in VB.Net and then to use like ocx in VB.6 but now I have another problem.I can not assign a click event or other events(in VB6) on this custom control.It only came with DragDrop ,DragOver,LostFocus,GotFocus and Validate events.
Did anyone know how can I do this?
Thx
This will be explained in the upcoming release, but here's the short answer.
(this is assuming you are using what Jon described in the post above -> the template you can download)
You have to specifically expose any events that you care about. Say you want to expose the usercontrol click event. To do this, in your usercontrol code, you can do something like
Public Event MyClickEvent()
and then in the usercontrol_click event, have code that looks like this:
Raiseevent myclickevent()
and when you compile this usercontrol and use it from VB6, you will see this event.
That's pretty much it...
Thank you for your answer.Yes it is working like you said , but only to see the event.
Let say:
I defined an event like you said
Public Event ClickEvent()
then on
usercontrol _click I raise the event ClickEvent like
RaiseEvent ClickEvent()
after that I build the usercontrol and when I use it in VB 6 I see the event ClickEvent
and I try to put some action on this event , but when I run the project and click on the usercontrol it do nothing .Why?
I have found that although it is possible to create a windows
control and register it as an activex com control that apparently
works under various applications using the template at
http://www.sweetpotatosoftware.com/SPSBlog/PermaLink,guid,3dd24f92-a52c-4bb0-8121-c2e6e2cc4f93.aspx
it may in effect be unreliable
and cause a fault in the client application such as Wonderware
Intouch View, when for example a method is executed
could you confirm this is by design, and which clients eg VB6
MFC7 and IE7
do support .NET controls and which clients will support
.NET controls created with the new beta version of Visual
studio
best wishes NIck
The link described above is an external post which describes a method similar (but different) than what we're working on. I have no comment on whether it works or not.
What we're working on is described in more detail here:
http://blogs.msdn.com/vbteam/archive/2006/11/02/interop-roadmap-usercontrols-mdi-and-data.aspx
and you can get an early prototype of what we're putting together.
As to what clients will be supported: We haven't made that determination yet, but currently, the only supported host for Winforms is IE. When we release this template, we obviously will support VB6 as a host, but that's all we'll be claiming to care about for now.
Toddap_MS
As to this question, I think (?) there may be some comments in the usercontrol telmplate code that explain this, but if not, here's a summary:
1) What you running into is a bug in windows forms. It is fixed and will be available in a GDR or a future release of the .net framework.
2) However, there's a relatively easy workaround that you can use today. Here it is:
a) Assuming your usercontrol project is named "mycontrollib" and your usercontrol class is "mycontrol"
b) From VB6, add the usercontrol to your toolbox and put an instance on the form
c) Goto add/remove project references dialog and add a reference to "mycontrollib" to your project (you will allready have one named Mycontrollibctl)
c) Add this code
Dim withevents a as mycontrollib.mycontrol
Private Sub Form_Load()
set x = me.mycontrol1 'or whatever your control instance name is
end sub
Private Sub a_Click()
msgbox "HI"
end sub
and if you run it, the click event will fire. Hope that makes sense.
Toddap_MS
It is working.Thank you very much!