Showing pop-up without loosing focus

Hi,
I got a c# application. I want to show a popup form without loosing focus from other application (for example if the user is typing in word, i don't want the focus to go to the popup).
I tried to show it with Form.Show() (in msdn they say it will show it as modeless) but it still loose the focus sometimes. (it's not consistent).
Is there any way to show the form without taking focus or to return focus to other window that had the focus

Thanks alot,
Hisham




Answer this question

Showing pop-up without loosing focus

  • Sonmez

    Have you tried to give focus to your hidden form That should pull the focus from the popup, then it will disregard the focus because it is hidden which should bring you back to the users application that is running.


  • Alexander Klizhentas

    Hi,

    Thanks for you reply.
    But what you did there was calling the Focus method with the main form that opened the popup. this way you recive back the focus. in my case it's different. i don't have an open form (it's hidden). My application is a status bar application, and i want to open popups (like MSN messenger popups). so i want to put focus back to the user's application (where it was before).

    Thanks alot,
    Hisham

  • Peter Poirier

    In VB you just have to set focus back to the main form. C# I don't think has the me namespace but you should get the idea. Also when you set the focus back to the main form it should go to the last control that had focus.

    I was able to have a popup window (form2) display a label whose text changed with each textchanged event in my form1 textbox control without loosing focus.

    Me.form2.Show()
    Me.Focus()

     

     

     

     

    ------------------

    'You could always use the Application.OpenForms too.

    Public Class Form1

    Dim form2 As New Form2

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    If form2.Visible = False Then

    Me.form2.Show()

    Me.Focus()

    End If

    form2.Label1.Text = Me.TextBox1.Text

    End Sub

    End Class


  • Showing pop-up without loosing focus