FlyBoy Posted October 30, 2004 Posted October 30, 2004 i have the following code,which creates a user control (created it using a book...that doesnt explain it.. :( ) . . . public event System.EventHandler LoginSuccess; public event System.EventHandler LoginFail; . . . private void loginClick(object sender, System.EventArgs e) { if (userNameText.Text.Length == 0) { loginError.SetError(userNameText, "Please enter a user name"); return; } if (passwordText.Text.Length == 0) { loginError.SetError(passwordText, "Please enter a password"); return; } if (userNameAndPasswordAreValid(userNameText.Text, passwordText.Text)) { if (LoginSuccess != null) { LoginSuccess(this, new System.EventArgs()); } } else { if (LoginFail != null) { LoginFail(this, new System.EventArgs()); } } } i cant figure the events : "LoginSuccess" and "LoginSuccess". where do they get info from that they can be cheacked for a null value??? :confused: 10x in advance. Quote
Joe Mamma Posted October 30, 2004 Posted October 30, 2004 loginFail and LoginSuccess are actuall pointers. . . pointers to a list of methods thate are members of other object instances. when you set an event for a control, you are actually adding a method to that list. checking for null is checking to see if you have 'wired' the events to any methods. If not null the event is fired, which calls each of the methods that are wired to the event. the event can be wired by dropping the control on a component and setting a handler method via the IDE or at runtime you could attach via: MyControl.MyEvent += new EventHandler(SomeClass.SomeMethod) I hope that makes sense. Everyone should own Lowy's Programming .Net Components (O'Reilly) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
FlyBoy Posted October 30, 2004 Author Posted October 30, 2004 loginFail and LoginSuccess are actuall pointers. . . pointers to a list of methods thate are members of other object instances. when you set an event for a control, you are actually adding a method to that list. checking for null is checking to see if you have 'wired' the events to any methods. If not null the event is fired, which calls each of the methods that are wired to the event. the event can be wired by dropping the control on a component and setting a handler method via the IDE or at runtime you could attach via: MyControl.MyEvent += new EventHandler(SomeClass.SomeMethod) I hope that makes sense. Everyone should own Lowy's Programming .Net Components (O'Reilly) yes abit....10x. but still i cant figure out,where the events gets theire values from? i mean....if the password validation method returns false or true i dont see it assigning anything to any of the events.... this is the password checking method...: private bool userNameAndPasswordAreValid(string name, string password) { return password.Equals("TrustMe"); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.