Problem solve Get help with specific problems with your technologies, process and projects.

Incorporating classes into a C# form

How do I incorporate classes into a Visual C# form?
Incorporating classes is just a matter of opening the form file in code view and declaring a variable of the type you wish to use:

private MyClass my = new MyClass();

If you're wondering why you can drop some things that are not controls on the form, it's because they're not regular classes but rather Components, which only differ with classes in that they inherit from a Component base class (directly or indirectly), which gives them more freedom to interact with the design-time form.

You won't see your variables (of regular classes) in design view, as they are just that, variables that have nothing to do with the form, unlike components, which are hooked to a form automatically by the InitializeComponent method (among other things).

Dig Deeper on C# programming language

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.