Win Form never gets focus?!?

Discussion in 'Microsoft Dot NET Framework Forms' started by Fre, Mar 12, 2008.

  1. Fre

    Fre Guest

    Hi all,

    In my winform application, I want to check on certain moments if my
    winform has focus. If so, some code will be executed. I noticed
    however, that the winform never gets the focus, even when it clearly
    has focus. How is that possible? What setting could I've messed with
    that causes my winform never to get focus, even when activated?

    void Form1_Activated(object sender, EventArgs e)
    {
    // always returns 'False' in my project (when I test
    // in new project, it returns 'True' however!!)
    Console.WriteLine("ACTIVATED & " + "this.Focused = " +
    this.Focused);
    }

    Thanks in advance for your answers.

    Frederik
     
    Fre, Mar 12, 2008
    #1
    1. Advertisements

  2. Try checking:

    if (Form.ActiveForm.Equals (this))
    ...

    instead of:

    if (this.Focused)
    ...

    /ravi

    ----------------------------
    "Fre" <> wrote in message
    news:...
    > Hi all,
    >
    > In my winform application, I want to check on certain moments if my
    > winform has focus. If so, some code will be executed. I noticed
    > however, that the winform never gets the focus, even when it clearly
    > has focus. How is that possible? What setting could I've messed with
    > that causes my winform never to get focus, even when activated?
    >
    > void Form1_Activated(object sender, EventArgs e)
    > {
    > // always returns 'False' in my project (when I test
    > // in new project, it returns 'True' however!!)
    > Console.WriteLine("ACTIVATED & " + "this.Focused = " +
    > this.Focused);
    > }
    >
    > Thanks in advance for your answers.
    >
    > Frederik
     
    Ravi Bhavnani, Mar 18, 2008
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page