469,626 Members | 1,518 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Form focuse

Why I can't catch the Form lost focuse event ?
I mad a FORM , I want to print message each time I moved to another
application my my desktop .
I thryed the following but not work .

this.LostFocus += new System.EventHandler(this.Form1_LostFocuse);

private void Form1_LostFocuse(object sender, System.EventArgs e)
{
MessageBox.Show("Write ");
}
Nov 17 '05 #1
5 1550
I also Tryed the Leave event also not work
"[Yosi]" wrote:
Why I can't catch the Form lost focuse event ?
I mad a FORM , I want to print message each time I moved to another
application my my desktop .
I thryed the following but not work .

this.LostFocus += new System.EventHandler(this.Form1_LostFocuse);

private void Form1_LostFocuse(object sender, System.EventArgs e)
{
MessageBox.Show("Write ");
}

Nov 17 '05 #2
Hi Yosi,

I see nothing wrong with your code.
If you copy those lines into a new blank Windows Form, do you get the same
(no event fired)?
If not, something else in your code is interfering, if you do you might
want to reinstall .net.

PS! The Enter/Leave events are for regular controls and should not be
used for Windows Forms, instead use the Activated/Deactivate events.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #3
When I add TextBox or Button this not work , when remove them this is work
Why ?

"Morten Wennevik" wrote:
Hi Yosi,

I see nothing wrong with your code.
If you copy those lines into a new blank Windows Form, do you get the same
(no event fired)?
If not, something else in your code is interfering, if you do you might
want to reinstall .net.

PS! The Enter/Leave events are for regular controls and should not be
used for Windows Forms, instead use the Activated/Deactivate events.

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 17 '05 #4
Hi,
I think I remember that somewhere in the documentation it says that
Form.Focus will not be fired when a control is added, In the MSDN from
form.focus says the same that morten said, use Activate
FROM MSDN:
Note The GotFocus and LostFocus events are low-level focus events that are
tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the
GotFocus and LostFocus events are only used when updating UICues. The Enter
and Leave events should be used for all controls except the Form class,
which uses the Activated and Deactivate events. For more information about
the GotFocus and LostFocus events, see the WM_SETFOCUS and WM_KILLFOCUS
topics in the Keyboard Input Reference section of the Platform SDK
Documentation in the MSDN Library.
Anyway I'm sure that I read somewhere explicitely they will not get fired,
use Activate/Deactivate instead

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"[Yosi]" <Yo**@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
When I add TextBox or Button this not work , when remove them this is work
Why ?

"Morten Wennevik" wrote:
Hi Yosi,

I see nothing wrong with your code.
If you copy those lines into a new blank Windows Form, do you get the
same
(no event fired)?
If not, something else in your code is interfering, if you do you might
want to reinstall .net.

PS! The Enter/Leave events are for regular controls and should not be
used for Windows Forms, instead use the Activated/Deactivate events.

--
Happy Coding!
Morten Wennevik [C# MVP]

Nov 17 '05 #5
Is there a way to catch these events at a higher level? I want to know
whenever any application is launched, focused, or exited, without having to
attach a form focus handler to each possible form. I really just want the
Windows Task Manager information as it happens. Is this possible? If so,
can you direct me to the API or sample code in C#?

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by John | last post: by
5 posts views Thread by Richard Cornford | last post: by
4 posts views Thread by Targa | last post: by
11 posts views Thread by Jozef | last post: by
2 posts views Thread by Mohammed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.