How to host .net UserControl in C ++ cdialog in visual studio 6

My task is quite simple to create a .net custom control and use it in the old visual studio 6 proejct.

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

.net looks like tihs:

dotnetcotrol namespace {

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 the same as in the ms example, but my project is an mfc project in a window.

0


a source to share


2 answers


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



However, the route I'll take to host a .Net control in a VC ++ 6 form is reverse engineering the source of the VC ++ CWinFormsUserControl class. If you have Visual Studio 2005 installed with VC ++ installed, you have the source of this class under% PROGRAMFILES% \ Microsoft Visual Studio 8 \ VC \ atlmfc \ src \ mfcm.

0


a source


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

Form.Controls.Add(myUserControl);

      



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

-2


a source







All Articles