473,236 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

Preventing a form from getting focus

Is there a way to prevent a form from getting focus?

Thanks!
- Pete
Nov 16 '05 #1
5 10080
"Petec" <x@x.x> wrote:
Is there a way to prevent a form from getting focus?


Why do you want to do this? There is probably a better solution than
preventing the user from doing what he wants to do.

P.
Nov 16 '05 #2
Paul E Collins wrote:
"Petec" <x@x.x> wrote:
Is there a way to prevent a form from getting focus?


Why do you want to do this? There is probably a better solution than
preventing the user from doing what he wants to do.

P.


I have a main form with a grid of items, and when the user hovers over an
item a ballon with a detailed description of the item pops up.
I'd like to prevent the balloon from getting focus, so that the main form
still has focus.

- Pete
Nov 16 '05 #3
"Petec" <x@x.x> wrote:
I have a main form with a grid of items, and when
the user hovers over an item a ballon with a detailed
description of the item pops up.
I'd like to prevent the balloon from getting focus, so
that the main form still has focus.


Hovering involves use of the mouse, so if the user then clicks on
something else, that click will give focus back to the main form
anyway.

If that's not good enough, I suppose you could make the balloon
'always on top' (TopMost property) and automatically restore focus to
the main form as soon as the balloon loads.

P.
Nov 16 '05 #4
I could be wrong, but I don't think there's any managed code to do this
unfortunately (I've been looking for a managed solution to this problem for
a long time.)

What you could do is make an API call to ShowWindow.

You first have to bring in ShowWindow in your source with something that
looks like this:

[DllImport("user32.dll")]
private static extern Boolean ShowWindow(IntPtr hWnd,Int32 nCmdShow);

Now you can use it. Instead of showing your form the conventional way, show
it like this:

ShowWindow(this.Handle, 4);

Now it will be shown without stealing focus.

I got this code from John O'Byrne from an excellent article on
CodeProject.com for an MSN-style skinnable popup window. You can find the
full source here:

http://www.codeproject.com/cs/miscct...arnotifier.asp

The only change that I'd recommend to stay consistent with Win32 programming
and keeping your code more elegant is to declare SW_SHOWNOACTIVATE as a
constant somewhere in your code instead of hardcoding "4" for the show
state.

ShowWindow(this.Handle, SW_SHOWNOACTIVATE);

Looks nicer. Otherwise that guy did a great job on his component and you
should check it out whether you need something like that or not.

Calling ShowWindow is a much better solution than setting focus back to the
main form, by the way. I've tried that. You get some problems with the
user's input being momentarily intercepted and flashing in some cases and
some obvious quirks. But the above works beautifully. I REALLY hope they
will provide a better solution for this in .NET 2.0, or perhaps wrap
ShowWindow() in WinFX.

"Petec" <x@x.x> wrote in message
news:d7****************@newsread1.news.pas.earthli nk.net...
Is there a way to prevent a form from getting focus?

Thanks!
- Pete

Nov 16 '05 #5
Thank you, that worked great!

- Pete

Eric wrote:
I could be wrong, but I don't think there's any managed code to do
this unfortunately (I've been looking for a managed solution to this
problem for a long time.)

What you could do is make an API call to ShowWindow.

You first have to bring in ShowWindow in your source with something
that looks like this:

[DllImport("user32.dll")]
private static extern Boolean ShowWindow(IntPtr hWnd,Int32 nCmdShow);

Now you can use it. Instead of showing your form the conventional
way, show it like this:

ShowWindow(this.Handle, 4);

Now it will be shown without stealing focus.

I got this code from John O'Byrne from an excellent article on
CodeProject.com for an MSN-style skinnable popup window. You can find
the full source here:

http://www.codeproject.com/cs/miscct...arnotifier.asp

The only change that I'd recommend to stay consistent with Win32
programming and keeping your code more elegant is to declare
SW_SHOWNOACTIVATE as a constant somewhere in your code instead of
hardcoding "4" for the show state.

ShowWindow(this.Handle, SW_SHOWNOACTIVATE);

Looks nicer. Otherwise that guy did a great job on his component and
you should check it out whether you need something like that or not.

Calling ShowWindow is a much better solution than setting focus back
to the main form, by the way. I've tried that. You get some problems
with the user's input being momentarily intercepted and flashing in
some cases and some obvious quirks. But the above works beautifully.
I REALLY hope they will provide a better solution for this in .NET
2.0, or perhaps wrap ShowWindow() in WinFX.

"Petec" <x@x.x> wrote in message
news:d7****************@newsread1.news.pas.earthli nk.net...
Is there a way to prevent a form from getting focus?

Thanks!
- Pete


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
5
by: Darren DeCoste | last post by:
I have an access project with a Form that has a Command button to print the current record. I would like to Print the record 3 times, changing a text field on each print. The standard code of...
8
by: Susan Bricker | last post by:
Hi. I am opening a form (frmUserSettings) just before (or so I thought) the Main Menu form (frmMainMenu) is opening but it's not getting the focus. It gets "painted" and then the Main Menu gets...
13
by: M O J O | last post by:
Hi, I need to create a popup form what will not steal focus. I've searched the net and I managed to put some code together. Below is the result of my code, but I have a single question .......
0
by: Dave | last post by:
Hello, I am writing an On-screen keyboard, similar to the one included in windows 2k and XP. The problem I am having is that I need my keyboard to never get the focus, but still be able to...
2
by: Khadim | last post by:
Hi, I am having this problem with my application that it is not getting itself in taskbar by itself.. i m working on this application for 5 months, don't know what happened at what time that its...
2
by: Sid Price | last post by:
Is there a way of stopping a form getting focus in VB.NET. The scenario I have is a main form and a form used for display only. There are no user controls on the display form and it does not ever...
3
by: sravan_reddy001 | last post by:
i want to prevent a form from closing.. to do this i want to handle the formClosing or FormClosed events. from here i want to prevent the form from closing. New instance of same form should...
2
by: Joergen Bech | last post by:
Hope someone has a solution or some suggestions for this. This cannot be right?!? Problem: I have multiple non-modal forms open at the same time. One or more of these forms have a...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.