code_junkie

control lost focus event when using keyboard shortcut

Nov 12th, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3. private Boolean _didLostFocusLogic;
  4.  
  5. public Form1()
  6. {
  7. InitializeComponent();
  8. }
  9.  
  10. private void textBox1_Leave(object sender, EventArgs e)
  11. {
  12. LostFocusLogic();
  13. }
  14.  
  15. private void button1_Click(object sender, EventArgs e)
  16. {
  17. ButtonClickLogic();
  18. }
  19.  
  20. private void LostFocusLogic()
  21. {
  22. /* Do stuff */
  23. _didLostFocusLogic = true;
  24. }
  25.  
  26. private void ButtonClickLogic()
  27. {
  28. if (!_didLostFocusLogic)
  29. LostFocusLogic();
  30.  
  31. _didLostFocusLogic = false; // Reset for next time.
  32.  
  33. /* Do stuff */
  34. }
  35. }
  36.  
  37. Button b = (Button) sender;
  38. b.Focus();
Add Comment
Please, Sign In to add comment