Control behaviour

J

Johnny Jörgensen

I've got a control class where I want a special action done after it is
instantiated. So I tried to insert a method call in the components
constructor after the initializecomponent call. Like this:

Public Sub New()

MyBase.New()

'This call is required by the Component Designer.

InitializeComponent()

DoMySpecial Stuff()

End Sub



Public Sub DoMySpecialStuff()

If SomePropertyOnWhichTheCodeIsDependent = True then
'Do Stuff
End If

End Sub


But that doesn't work as I want, because of course the constructor and the
initializecomponent is called before the properties are set. So when my code
is run, the properties still have their default values. If it was only ONE
property, I could just call my code in the Property set method, but I've got
around 10 properties that need to be set before calling the code.

How can I assure that all properties have been set before calling my code?
Of course, the property set method is only called by the form designer code
if it is serialized, meaning that it doesn't have it's defaultvalue. So I
can't put code in the property set method to later check if the property is
set, because it might or might not have been called, and even if it hasn't
been called, the property still has the right value.

I hope you understand my problem.

Has anybody got a good idea?

Cheers,
Johnny J.
 
J

Jack Jackson

I've got a control class where I want a special action done after it is
instantiated. So I tried to insert a method call in the components
constructor after the initializecomponent call. Like this:

Public Sub New()

MyBase.New()

'This call is required by the Component Designer.

InitializeComponent()

DoMySpecial Stuff()

End Sub



Public Sub DoMySpecialStuff()

If SomePropertyOnWhichTheCodeIsDependent = True then
'Do Stuff
End If

End Sub


But that doesn't work as I want, because of course the constructor and the
initializecomponent is called before the properties are set. So when my code
is run, the properties still have their default values. If it was only ONE
property, I could just call my code in the Property set method, but I've got
around 10 properties that need to be set before calling the code.

How can I assure that all properties have been set before calling my code?
Of course, the property set method is only called by the form designer code
if it is serialized, meaning that it doesn't have it's defaultvalue. So I
can't put code in the property set method to later check if the property is
set, because it might or might not have been called, and even if it hasn't
been called, the property still has the right value.

I hope you understand my problem.

Has anybody got a good idea?

Cheers,
Johnny J.

You could implement the ISupportInitialize interface and put your code
in the EndInit() method. The IDE wraps the setting of properties with
calls to BeginInit() and EndInit().
 

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