Forcing a form to get the focus

kirkside

New member
Joined
Jul 24, 2006
Messages
2
Programming Experience
Beginner
Hi all,

I have created a simple popup form that rather nicely fades in to the screen for the user. It has a 3 hour countdown on. I have not forced it to stay on the screen the whole time so that the user can carry on working. Every 30 minutes I want the form to fade in on top of the running applications to remind the user of the countdown.

Unfortunately, I cannot seem to get the form to show up. I have tried me.show() and me. Focus=true but it does not work. I have resorted to forcing the form to minimize and than restore to normal using the code below.

Me.WindowState = FormWindowState.Minimized
Me.WindowState = FormWindowState.Normal

This causes some rather annoying flickering of the screen and I would rather the form was to simply fade in to view.

Can anyone give me some suggestions?

Cheers.
 
I have just played with Me.TopMost which has actually worked. You learn something new everyday.

Thank you for the reply though.
 
BringToTop method is for controls on forms, not the forms themselves.
TopMost is not what you want, read the docs about its meaning.

Me.Activate (or forminstance.Activate) will bring the form from back to the foreground.
 
I think me.activate will also give the that form the focus and may annoy the user. TopMost may be the right answer so that the user can continue working with their current project and then simply get the reminder and continue on. of course I don't know the full course of action but from what I am gathering he simply wants to show the user the amount of time left w/o taking away from their current work. But JohnH has taught me quite a bit so maybe activate is the correct answer in this situation. I know he is correct in what Activate does.
 
Setting property TopMost does the exact same interuption by making itself the foremost window, only when user tries to move on, that window stays like a tool window defocused at top. So if the reminder is badly placed too, the user will not be able to continue by clicking at the working window, but must also close or move the reminder away before continueing work. But if keeping a constant reminder is wanted TopMost is the choice.
 
note also that it is possible to:

make a form semi transparent
have it relay any clicks on it, to the windows underneath...


i did this with an old VB6 app with some API calls, im sure its avail in .NET the same way or maybe a wrapped .NET way...

the upshot is you can have a form on screen, reasonably visible, but what is underneath can still be seen and clicked on and interacted with in the usual way - as if the form wasnt there... mmmh, very cool! :)
 
About transparency just set the forms Opacity property. You can also combine with setting the Region for the form, it can be done quite cleverly for example only a string path and some handles visible. Simple example:
VB.NET:
Me.Opacity = 0.5
Dim gp As New Drawing2D.GraphicsPath()
Dim rct As New Rectangle(0, 0, Me.Bounds.Width, Me.Bounds.Height)
gp.AddEllipse(rct)
Dim r As New Region(gp)
Me.Region = r
I don't think you can relay mouse through the window to window behind (at least that doesn't sound viable), but I've seen similar feature where such application fades quickly away when hovering it for a second (or some 'away' gesture), then returns for some time/logic..
 
Well, you can have a click thorugh forms, but you would have the forms opacity set to zero or as near as. Which means that you wouldn't be able to see it anyway, so it may as well be hidden.
 
form.Opacity = 0 makes a hidden form, I didn't find it anyway. lol :)
 
JohnH said:
I don't think you can relay mouse through the window to window behind (at least that doesn't sound viable), but I've seen similar feature where such application fades quickly away when hovering it for a second (or some 'away' gesture), then returns for some time/logic..

I kid ye not.. i've written such an app to help me at work. It occasionally floats popup messages on screen such as every 2 hours asking me my programming task (time tracking) or on request, it pops stuff like employee phone numbers and other kinds of messages..

One of the features I was most proud of was that if the user rolled the mouse over the form it would slowly fade to ~30% transparent and stay that way for a few seconds after they rolled away - still visible but apps underneath became usably visible.. and in addition to this the form would transmit mouse messages such as clicks, through to the form below. I've just checked and the app underneath starts responding to mouse clicks as soon as the form starts to fade, so whatever technique I used allowed click-through regardless of opacity. It also slid on and off screen all off the one timer.. Some squiggly code, i can tell you!

Sadly, I dont think I can go into any more detail because the source code for the app was lost to hard drive failure.. And it was this event (losing 3 years coding on minor apps and helper stuff, among other things) that actually made me take a few hours out my life to set up a backup schedule.. :/
The app still exists, so if someone wants to see it, and has an oracle instance lying around, I'll happily send it along.. :)

If i ever find the backup i think i have lying around, i'll post the code (it's VB6 but the trans/clickthrough was done with API calls)
 
Another nifty solution may be to just move the form to another part of the screen when the mouse moves onto it. That way you never get the mouse on it, or on it long anyways, not long enough to notice.
 
Back
Top