Is there a C# equivalent of RUNTIME_CLASS ?

I

Ian Semmel

In C++, I would typically have a static table of elements like

typedef struct CIconListBoxItem
{
LPCTSTR pszText;
UINT image;
UINT messageID;
bool bDisable;
CRuntimeClass* pView;
}CIconListBoxItem;

where pView is initialised to RUNTIME_CLASS(MyForm)

and will create the form with Createview

Is there an equivalent in C# whereby I can put the class of form I want in a
table and create it as needed ?
 
L

Lebesgue

I don't fully understand the purpose of C++ code you have provided, but if I
understand what you need, the answer is yes, you can store the Type of the
form and create it later.
By Type, I mean System.Type, and by creating, I mean creating an instance of
the specified Type with Activator.

your data structure would like as follows:

class Foo
{
public Type FormType;
}

void CreateAndShowFormFromFoo(Foo foo)
{
Form f = (Form)Activator.CreateInstance(foo.FormType);
f.Show();
}
 
I

Ian Semmel

Yes, that's exactly what I wanted, thanks.

Incidentally, it seems to me, that now I am switching forms using this method,
that it is a bit slower. I'm not sure, but I'm not going back to check it out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top