1 Replies - 4922 Views - Last Post: 16 January 2008 - 02:45 AM Rate Topic: -----

#1 Agalo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-November 07

Hot key problem

Posted 15 January 2008 - 10:54 PM

In my project i have a textbox and a button. i have a hot key for button.
there are 2 events , one is textbox Leave event and other is button Click event.

2 scenarios which should give same result but are differently behaving.

case 1 :
when cursor in in textbox and i press button with help of mouse .
then textBox leave event is fired.

case 2:
when cursor in in textbox and i press hot key for button then button click event is fired.

I expected simmilar results but outcome was different.

can anyone explain why this is happening and how to handle hot key to have same behaviour as button click with mouse ?
is it because when we use hot key it doesn't have information about cursor ??
please help. ......

Is This A Good Question/Topic? 0
  • +

Replies To: Hot key problem

#2 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: Hot key problem

Posted 16 January 2008 - 02:45 AM

It looks like you're trying to fire a leave event!

The reason this didn't work is because the focus never left the TextBox.

When you are in the text box, and then click on the button, the focus changes from the text box (firing the leave event) then the button is clicked (firing the click event).

If you use the hot key, the focus never leaves the text box, so the leave event is not fired.

If you want that to happen, simply set the focus to the button, as the first thing inside it's code.

So say you have a button called "btnTest", with the text "Test", then the following code will work:

	private void btnTest_Click(object sender, EventArgs e) {
	  btnTest.Focus();
	  ...
	  ...
	}



This basically changes the focus from whatever, to the button. So if the focus is inside the textbox, the textbox.leave event should be fired before the rest of the code in the click event is executed.

Hope that explains and helps.
Was This Post Helpful? 1

Page 1 of 1