Launch a window that stays topmost but doesn't steal focus

  • Thread starter Thread starter sstory
  • Start date Start date
S

sstory

I have a listener app, that listens for a network message. For certain
messages it needs to display something to the user, but I'd like that to be
topmost, and at the top of the screen about the size of the title bar of a
window. I have it sized and positioned right and topmost, but can't seem to
keep from stealing the focus.

How can I accomplish this?

Thanks

Shane
 
I have a listener app, that listens for a network message. For certain
messages it needs to display something to the user, but I'd like that to be
topmost, and at the top of the screen about the size of the title bar of a
window. I have it sized and positioned right and topmost, but can't seem to
keep from stealing the focus.

How can I accomplish this?

Thanks

Shane

If i undestood correct, you want your application to be on top
everytime. Right? If so, simply drag a timer control from toolbox then
don't forget to set timer's default mode to "enabled", double-click on
timer and put the code on timer1_tick event:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Me.TopMost = True
End Sub

This "topMost" property makes your form available on top unless it
minimized.

Another approach is to force the form to be activated everytime as
follows:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Me.Activate()
End Sub

This method may not make your app to be on top everytime, but
indicates that your app wants to be on tap by flashing on taskbar.
 
Thanks for the reply. No I already have the app said to TopMost.
what I want to do is display a message on top that the user can read,
without interrupting what they are doing by stealing the focus.

I want the window they are in to remain the active window, but my window to
display on top as a little popup.
 
Thanks for the reply. No I already have the app said to TopMost.
what I want to do is display a message on top that the user can read,
without interrupting what they are doing by stealing the focus.

I want the window they are in to remain the active window, but my window to
display on top as a little popup.

Hi,
Well, couldn't make out your issue well but if you just want to notice
users without interrupting their works on computer, you can put a auto-
close code to your form, for this purpose still timer control is good,
before this set the "interval" of your timer to an desirable level for
auto-close.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TopMost = True
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Me.Close()
End Sub

If you want users to close your notification window, simply place a
button and add "me.close" inside button.click event.

Sorry if i understood wrong.

Hope this helps.
 
Actually this pop up is a YES NO question. It needs to wait until someone
clicks it, but they should be able to ignore it and continue working until
they choose to click--thus it shouldn't become the active window and take
the focus.
 
Actually this pop up is a YES NO question. It needs to wait until someone
clicks it, but they should be able to ignore it and continue working until
they choose to click--thus it shouldn't become the active window and take
the focus.












- Show quoted text -

Then why don't you put "me.deactivate" on form_load event? It may help
you.
 
Actually this pop up is a YES NO question. It needs to wait until someone
clicks it, but they should be able to ignore it and continue working until
they choose to click--thus it shouldn't become the active window and take
the focus.

There is a form property you can override that prevents the form from
stealing focus. Add the following overrides to the form code and it
should help:

///////////////
Protected Overrides ReadOnly Property ShowWithoutActivation() As
Boolean
Get
Return True
End Get
End Property
///////////////

Thanks,

Seth Rowe [MVP]
 
I don't see a me.deactivate. When I do me.dea, there is is no intellisence
that suggests there is a me.deactivate


Actually this pop up is a YES NO question. It needs to wait until someone
clicks it, but they should be able to ignore it and continue working until
they choose to click--thus it shouldn't become the active window and take
the focus.












- Show quoted text -

Then why don't you put "me.deactivate" on form_load event? It may help
you.
 
I don't see a me.deactivate. When I do me.dea, there is is no intellisence
that suggests there is a me.deactivate






Then why don't you put "me.deactivate" on form_load event? It may help
you.

Sorry, my fault, i meant you could use "mybase.deactivated" evant
handler:

Private Sub Form1_deactivate(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate

' put here the code when you form is deactivated by user, you can put
nothing or a msgbox that is YesNO style.

End Sub
 
I have an app that shows a window that I want to have a message that is a
YES/NO question.
It looks like this:

------------------------------------------------------------------------------------------------------------------------
| Can you go eat at 12:00?
[yes] [no] |
------------------------------------------------------------------------------------------------------------------------

This is a vb form with no border, positioned with top=0, left being such
that it is centered. It should be topmost to all windows.
I want the user to see it, but be able to keep working in whatever app they
are currently using without being rudely interrupted.
Of course the questions actually asked are different and business related.
Therefore the window needs to show but not be Active--i.e. not steal the
focus.

I have tried everything I can think of including showing it with
ShowWindow() API with SW_SHOWNA and other API's.
This seems to show it, but then it won't show anything in the form i.e. the
text or buttons. And it shows an hourglass as if it is hung.
To be sure that showing the form via ShowWindow wasn't hanging up the
textbox and button controls, I got rid of them and am now painting the text
to the form in the Paint event with DrawString and drawing the graphics for
yes and know, doing hit testing and such...so there are NO controls now.
This still doesn't work.

Does anyone know how to do this?

Thanks
 
I have an app that shows a window that I want to have a message that is a
YES/NO question.
It looks like this:

------------------------------------------------------------------------------------------------------------------------
| Can you go eat at 12:00?
[yes] [no] |
------------------------------------------------------------------------------------------------------------------------

This is a vb form with no border, positioned with top=0, left being such
that it is centered. It should be topmost to all windows.
I want the user to see it, but be able to keep working in whatever app they
are currently using without being rudely interrupted.
Of course the questions actually asked are different and business related.
Therefore the window needs to show but not be Active--i.e. not steal the
focus.

I have tried everything I can think of including showing it with
ShowWindow() API with SW_SHOWNA and other API's.
This seems to show it, but then it won't show anything in the form i.e. the
text or buttons. And it shows an hourglass as if it is hung.
To be sure that showing the form via ShowWindow wasn't hanging up the
textbox and button controls, I got rid of them and am now painting the text
to the form in the Paint event with DrawString and drawing the graphics for
yes and know, doing hit testing and such...so there are NO controls now.
This still doesn't work.

Does anyone know how to do this?

Thanks


Sorry, my fault, i meant you could use "mybase.deactivated" evant
handler:
Private Sub Form1_deactivate(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate
' put here the code when you form is deactivated by user, you can put
nothing or a msgbox that is YesNO style.

Did you try my code?

Thanks,

Seth Rowe [MVP]
 
The solution is to make a sub that launches the form, that reads a global
variable with the message, putting a thread lock around that.
In the sub is one a separate thread and launches the form by
form1.showdialog.

This works just like I wanted it to. The solution is to launch it on a
separate thread.

thanks to all of your input
 
The solution:

The form must be started from a new thread--apparently. I made a sub that
starts this message form as non-activated.

Next I called that sub as the entry point of a new thread and everything
worked as desired.
 
Back
Top