0

I have a Generic UserControl as blow:

 public partial class TreeNodeView<C,T>: UserControl 
    {
        public TreeNodeView(C foo, T foo1)
        {
            InitializeComponent();
        }
    }

Either change the partial class as below:

partial class TreeNodeView<C, T>

And because get this error in partial designer class:

Using the generic type 'TreeNodeView' requires 2 type arguments

in line :

System.ComponentModel.ComponentResourceManager resources = 
new System.ComponentModel.ComponentResourceManager(typeof(TreeNodeView));

change it to:

System.ComponentModel.ComponentResourceManager resources = new 
System.ComponentModel.ComponentResourceManager(typeof(TreeNodeView<C,T>));

The code compile successful but when want to see the designer i see ma messagebox:

a new guard page for the stack cannot be created

and when press OK visual studio close immediately. Anybody know whats my wrong?

Ali
  • 3,373
  • 5
  • 42
  • 54

1 Answers1

3

You can't design a control which is a generic type. This is not supported by the WinForms Designer.

Either change your control to a non-generic type and use generic methods instead, or try to design a derived type of which is not generic anymore.

Toni Wenzel
  • 2,081
  • 2
  • 24
  • 39
  • Your TreeNodeView is a generic type. – Toni Wenzel Jul 06 '17 at 17:15
  • See https://stackoverflow.com/questions/677609/generic-base-class-for-winform-usercontrol or https://msdn.microsoft.com/en-us/library/ms379564(v=vs.80).aspx – Toni Wenzel Jul 06 '17 at 17:21
  • @ToniWenzel Whats your opinion about the [answer](https://stackoverflow.com/a/677639/4972721) of the question you mention in last comment – Ali Jul 06 '17 at 17:40