[Mono-winforms-list] Find out if the application window is focused/active

Stifu stifu at free.fr
Sun Jun 21 05:34:42 EDT 2009


Never mind, I found something that works!
I use this instead:

if (Form.ActiveForm != null)

MSDN says: "A Form that represents the currently active form, or a null
reference if there is no active form."

So that seems good to me.


Stifu wrote:
> 
> Me again, for the same problem.
> 
> this.ActiveControl.Focused worked fine back when I had all of my controls
> in the same MainForm class.
> Now I made my own UserControl which is added to my MainForm.
> Like before, I need to know if the application window is focused, but this
> time I have to do it from the UserControl rather than from the MainForm,
> and I can't manage to do it.
> 
> this.ActiveControl.Focused doesn't work, because this.ActiveControl is
> null in the UserControl.
> So I tried this.ParentForm.ActiveControl.Focused, which only works until I
> focus another control in the UserControl, then it always returns false. (I
> also tried (this.ParentForm as MainForm).ActiveControl.Focused, but no
> difference)
> 
> Any idea?
> 
> Thanks!
> 
> 
> Stifu wrote:
>> 
>> Many thanks! :)
>> 
>> 
>> Andreia Gaita wrote:
>>> 
>>> On 2/8/09, Stifu <stifu at free.fr> wrote:
>>>>  Long story short, I have the exact same problem as the one described
>>>> here:
>>>>  http://bytes.com/groups/net-c/760728-application-focus
>>>>  I want to know if my application window is currently focused/active,
>>>> but
>>>>  doing this.Focused doesn't return true if one the child controls of
>>>> the
>>>>  application is focused.
>>> 
>>> Off the top of my head, this.ActiveControl.Focused
>>> 
>>> andreia gaita
>>> _______________________________________________
>>> Mono-winforms-list maillist  -  Mono-winforms-list at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-winforms-list
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Find-out-if-the-application-window-is-focused-active-tp21897934p24132853.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.



More information about the Mono-winforms-list mailing list