Form.ActiveForm for C# control on a VB 6 form

  • Thread starter Thread starter ramhog
  • Start date Start date
R

ramhog

Hello all,
I have a C# control that is housed on a form that was created in VB 6.
There are some activities I want to do only if the control is on the
ActiveForm. However, since the form is a VB 6 form when I call
Form.ActiveForm I get a null back, even though I can see the form is
the active windows form. Is there a good way to get the ActiveForm in
this scenario?

Thank you.
 
ramhog,

How did you get the .NET control onto a form in VB6? .NET doesn't
support exporting ActiveX controls, although it is possible (but not
recommended).

In this scenario, ActiveForm is not going to work, as .NET keeps track
of which window handles have .NET window representations attached to them.
Since the VB6 form is not in .NET, there is no form to return.

Hope this helps.
 
Thank you for your response.

I understand it isn't recommended, probably because of issues just like
this. You can do this by creating the .NET control make it COM visible
and give it a ProgID and GUID, then you can create it in VB 6. I just
need to find a way to get the Handle to the form containing it, even if
that answer is in using an API.

ramhog,

How did you get the .NET control onto a form in VB6? .NET doesn't
support exporting ActiveX controls, although it is possible (but not
recommended).

In this scenario, ActiveForm is not going to work, as .NET keeps track
of which window handles have .NET window representations attached to them.
Since the VB6 form is not in .NET, there is no form to return.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


ramhog said:
Hello all,
I have a C# control that is housed on a form that was created in VB 6.
There are some activities I want to do only if the control is on the
ActiveForm. However, since the form is a VB 6 form when I call
Form.ActiveForm I get a null back, even though I can see the form is
the active windows form. Is there a good way to get the ActiveForm in
this scenario?

Thank you.
 
ramhog,

Why not just call the GetParent api method and pass your window handle
into it?

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

ramhog said:
Thank you for your response.

I understand it isn't recommended, probably because of issues just like
this. You can do this by creating the .NET control make it COM visible
and give it a ProgID and GUID, then you can create it in VB 6. I just
need to find a way to get the Handle to the form containing it, even if
that answer is in using an API.

ramhog,

How did you get the .NET control onto a form in VB6? .NET doesn't
support exporting ActiveX controls, although it is possible (but not
recommended).

In this scenario, ActiveForm is not going to work, as .NET keeps
track
of which window handles have .NET window representations attached to
them.
Since the VB6 form is not in .NET, there is no form to return.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


ramhog said:
Hello all,
I have a C# control that is housed on a form that was created in VB 6.
There are some activities I want to do only if the control is on the
ActiveForm. However, since the form is a VB 6 form when I call
Form.ActiveForm I get a null back, even though I can see the form is
the active windows form. Is there a good way to get the ActiveForm in
this scenario?

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top