M
marcin.rzeznicki
Hello,
I noticed very strange behavior while setting Site property of Control,
and I don't know how to solve that problem. here goes the stroy: I have
written my custom control - assume its type is C - and some class which
implements IComponent and IContainer - that container is going to
contain controls of type C. I have also implementted ISite interface to
serve as a link between C and container of mine. So far so good, yet
whenever I try to set Site property of instance of C (for example, when
adding to container), there comes shiny InvalidCastException out of
System.Windows.Forms.dll. Why is that? I do not know - Component should
not assume anything special about container to which it belongs and
definitely should behave in graceful manner when put in "wrong
environment", as component is by definition REUSABLE and reusability
means also cooperation with different surroundings. Yet it seems to me
that Control shuns that renowned idea... So goes the question - already
specified in the subject - how should I set Site for my control?
I noticed very strange behavior while setting Site property of Control,
and I don't know how to solve that problem. here goes the stroy: I have
written my custom control - assume its type is C - and some class which
implements IComponent and IContainer - that container is going to
contain controls of type C. I have also implementted ISite interface to
serve as a link between C and container of mine. So far so good, yet
whenever I try to set Site property of instance of C (for example, when
adding to container), there comes shiny InvalidCastException out of
System.Windows.Forms.dll. Why is that? I do not know - Component should
not assume anything special about container to which it belongs and
definitely should behave in graceful manner when put in "wrong
environment", as component is by definition REUSABLE and reusability
means also cooperation with different surroundings. Yet it seems to me
that Control shuns that renowned idea... So goes the question - already
specified in the subject - how should I set Site for my control?