Tanner.R
Tanner.R

Reputation: 479

Can add custom control to ToolBox, but cannot create dynamically?

I've created my own custom control and added it to my toolbox. It works, I can drag it to the Form, access its properties though code ect... But I cannot create it dynamically? Like for instance a button would be:

Button btn = new Button();

But when I try my control:

CustomControl x = new CustomControl();

I get: "Type or namespace name 'CustomControl' could not be found"

I add the .dll to my references and I try the above code, to only get: "'CustomControl' is a 'namespace' but is used like a 'type'"

What am I missing here?

Thanks

Upvotes: 0

Views: 394

Answers (2)

Ahmadali Shafiee
Ahmadali Shafiee

Reputation: 4657

I think you are using namespace instead type. namespace is just a Case and you can not create a new one using the last namespace. try to find what class is in the namespace and construct a new one(using CustomControl.Cl c=new CustomControl.Cl(); but not try to use CustomControl x = new CustomControl();


I think the reason is that the namespace does not have any constructor ant it can't construct but class have constructor. because the namespace's concept if for Classification your classes and another things and it doesn't exist int the general code.

Upvotes: 0

Jesse
Jesse

Reputation: 307

It sounds like maybe your CustomControl is in a namespace called CustomControl. If that's the case, then rename one of them.

Upvotes: 1

Related Questions