tags:

views:

178

answers:

2

Hi

My task is pretty simple create a .net usercontrol and use it in a old visual studio 6 proejct.

I have createt the usercontrol (its just a user control with a label), I then followed this guide (http://support.microsoft.com/kb/828736) and it seems to work fine. But how can I display the usercontrol? Do I have to use CreateControl, and how should I do that?

The .net looks like tihs:

namespace dotnetcotrol {

public interface dotnetcontrol
{
    void setText(string str);
}
public partial class dontnetcontrolClass : UserControl, dotnetcontrol
{

    public dontnetcontrolClass()
    {
        InitializeComponent();
    }

    public void setText(string str)
    {
        label1.Text = str;
    }
}

}

And the c++ code looks almost like the one in the ms example however my project is a a window mfc project.

A: 

UserControls are added to forms to be displayed, not simply "shown"

Form.Controls.Add(myUserControl);

However, this will be different if you're using a form that is not also .NET

McAden
The window where the usercontrol is to be added, is created in visual studio 6, and is not a .net form but an old c++ window/dialog
CruelIO
A: 

For something this simple, why not write your own class that inherits CWnd? Is there a reason the control needs to be a .Net UserControl?

That said, the route I would take to host a .Net control on a VC++ 6 form would be to reverse-engineer the source of the VC++ 8 (VC++ 2005) CWinFormsUserControl class. If you have Visual Studio 2005 with VC++ installed, you have the source to this class under %PROGRAMFILES%\Microsoft Visual Studio 8\VC\atlmfc\src\mfcm.

Aidan Ryan