Resolved Form is not handling the event of a custom class

pizzaboy

Well-known member
Joined
Jan 5, 2008
Messages
57
Programming Experience
1-3
I have a custom class which basically manages the program settings.

In it's New() event, I'm performing a check to see whether a value stored in My.Settings is the same as the default value (I made sure the value wasn't!), if not then it will perform a RaiseEvent ValueChanged().

On my form, I have an instance of the class declared "Private Withevents ProgramSettings as New clsProgramSettings", I also have a handler "Private Sub DoSomething() Handles ProgramSettings.ValueChanged" declared.

When I run the program the form gets loaded, the instance is created, the RaiseEvent is called, but the handler is not receiving the event?

I tried "Private Withevents ProgramSettings as clsProgramSettings", then creating the instance in the Form.Load(), but still no success!?

Is there something I'm doing wrong, or is there a problem with the IDE? I'm using VS 2010.

Any help would be greatly appreciated.

Thanks.
 
Last edited:
How can a handler receive instance events for an object instance that is yet not created? RaiseEvent Statement Read the note about constructors.
 
Thanks JohnH.

Think you misread my message a little... I did ALSO try creating the instance of ProgramSettings in the Form.Load() event aswell...
I tried "Private Withevents ProgramSettings as clsProgramSettings", then creating the instance in the Form.Load(), but still no success!?

Anyways, as you did help to confirm it wasn't a problem with my code via the MSDN link (I was looking up the Withevents help, doh!), but it appears that VS 2010 doesn't like events to be raised in class New() events!?!??

I solved the problem by creating a new subroutine, moving my code check into it and then calling the routine via the Form.Load().

Thanks again.
 

Latest posts

Back
Top