if Cancel is clicked TextBox Lost Focus event should not be called

mwaqasaziz

New member
Joined
Jan 2, 2014
Messages
3
Location
Lahore
Programming Experience
Beginner
i need help here

suppose i put

on textbox_lostfocus

msgbox("i am losing focus")



but now i want that if cancel btn is clicked this textbox lost focus event should not be called

and when i will click cancel the courser will be in that textbox

need code
 
Firstly, you should not be handling the LostFocus event of a TextBox to begin with. As the documentation states, you handle the Leave event if you want to do something every time focus leaves a particular control. If you don't want to do something EVERY time focus leaves a control then you don't handle Leave either.

You can handle the Validating event to perform validation and prevent a control losing focus if it fails. You can handle the Validated event to execute every time a control passes validation. If you then set the CausesValidation property of a Button to False and click it, the control that previously had focus will raise its Leave event but not its Validating or Validated event. That's how you implement a Cancel button on a dialogue and let the user exit even if the data is not valid.

What you're asking for sounds a bit odd. Why exactly do you want the user to click Cancel but still keep the same form open and the same control focused? Is your cancellation just supposed to clear the form data or something? If that's the case then you will have to either set focus back to the previous control or else stop the Button taking focus when you click it. Both are possible but let's not waste time with non-necessities. Please provide a FULL and CLEAR description of what you're trying to achieve, which includes what and why rather than just how, and then we can provide the most appropriate advice.
 
ok here is what I want to do I am really a starter so forgive me if its wrong

MyQuestion.png

please help
 
Well, the first thing that strikes me about that is that if someone can guess another user's login name you just give them the email address and phone number to go with it, even if it's not theirs, and they then know what email address to try to get the password from. I'm not trusting you with my private information.

Anyway, if the user clicks Cancel then they obviously don't want to have a password sent out to them so why would you want to focus the Login Name field? You should do as I've already described: handle the Validated event of the TextBox and set the CausesValidation property of the Button to False. This is exactly the type of scenario that those members were designed for.
 
- E-mailing a password = bad. Send a link to a password reset script instead.
- The only thing you need to have is an e-mail address. The rest is useless and dangerous to show as pointed out above.
 
Back
Top