473,545 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I set constant focus on windows form

sam
hi,
How to set constant focus on window form in c#.

cheers

Sam
Nov 23 '05 #1
4 14959
What do you mean by "constant focus"? Is that a window that can never be
hidden? (ie shows on top of other windows regardless)

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #2
sam
Yes, window that can never be hidden and lose focus. In another words i want
focus on my window form1 for all times even if mouse clicks on other
windows, focus should be on the window form1.
I hope it will be clear to u

cheers,

Sam

"vooose" <no****@microso ft.com> schreef in bericht
news:O4******** ******@TK2MSFTN GP12.phx.gbl...
What do you mean by "constant focus"? Is that a window that can never be
hidden? (ie shows on top of other windows regardless)

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***

Nov 23 '05 #3
sam,

I don't think this is possible. Back in the time of win16 applications there
was a "system modal" style dialogs. They was meant to be used exactly for
this. However this style was deprecated for Win32 because such application
may cause the whole system to lock up. Actually Windows tries to make sure
that any application can be deactivated so the control cannot be taken over.

Speaking of .NET there is no even managed solution for activating an
application. If one wants to do that one needs to resort to using PInvoke
and calling Win32 API methods.

I played little bit with this and the following is the code I get not too
bad results with. To play with this code create new empty winforms project,
set the TopMost property of the form to *true*, copy and paste this code
into the form's class, add a timer (timer1) and hook its Tick event to the
timer1_Tick method. You shold add *using* clause for
System.Runtime. InteropServices namespace.

private const int WM_ACTIVATEAPP = 0x001C;
[DllImportAttrib ute( "User32.dll " )]
private static extern int SetForegroundWi ndow( IntPtr hWnd );

protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_ACTIVATEAPP && ((int)m.WParam) == 0)
{

this.timer1.Int erval = 1;
this.timer1.Sta rt();
}
}

private void timer1_Tick(obj ect sender, System.EventArg s e)
{
this.timer1.Ena bled = false;
SetForegroundWi ndow(this.Handl e);
}

Using timer may look wierd, but my tests show that we need to give windows
some time after sending WM_ACTIVATEAPP to set up all the active/inactive
window stuff otherwise the result is not as good.

Again keep in mind that this is not the best solution possible. I believe
better results can be achieved installing WH_CBT hook. The problem is that
global CBT hook cannot be written in managed code, therefore the hook needs
to be written in native code and compiled in native DLL then the hook can
control activating and deactivating windows.

BTW why don't you create a full screen application that covers the whole
desktop. This way at least you can make activating via mouse clicks
inconvenient.
--

Stoitcho Goutsev (100) [C# MVP].

"sam" <s@s.com> wrote in message
news:e4******** ********@TK2MSF TNGP15.phx.gbl. ..
Yes, window that can never be hidden and lose focus. In another words i
want
focus on my window form1 for all times even if mouse clicks on other
windows, focus should be on the window form1.
I hope it will be clear to u

cheers,

Sam

"vooose" <no****@microso ft.com> schreef in bericht
news:O4******** ******@TK2MSFTN GP12.phx.gbl...
What do you mean by "constant focus"? Is that a window that can never be
hidden? (ie shows on top of other windows regardless)

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***


Nov 23 '05 #4
Sam have you tried ShowDialog()?

This will kind of do what you want if you want your form to be on top
and remain focused within your application *only*

(ie you can still click on other applications and give them focus)

If you require no other application to have focus then it certainly is
unusual, aggressive functionality!

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #5

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

Similar topics

4
2383
by: Scott Navarre | last post by:
Hi, I have Red Hat 8.0 and have the default Mozilla browser that comes with it. I am programming in javascript and have come across something problematic. Given the following code: <HTML> <HEAD> </HEAD> <BODY> <FORM>
0
2106
by: Vinod. | last post by:
Hi all, I have added browser control to a windows form. I am loading pages having multiple frames. I have noticed that the focus in a text is not maintained when the application is deactivated. I fixed this issue by finding the active element in dom and then setting its focus. If the active element is a frameelement then I get the document...
13
2301
by: Mike L | last post by:
I have a child form frmDataEntry call up another child form frmDealerSearch. If the user clicks on cancel on frmDealerSearch, I want to close frmDealerSearch and put the focus on txtDealerNum on frmDataEntry. Here is my code. public class frmDataEntry : System.Windows.Forms.Form { private void txtDealerNum_Leave(object sender,...
8
1996
by: copyco | last post by:
I want to be able to test if my app's form has focus, (ie: not in background, behind other windows). How can I do this? I tried the Me.Focused, but that doesn't work. I think it's because a control within the form actually has focus, so the Me.Focused would return false. Thanks!
1
6334
by: mongphong28 | last post by:
Hi, I'm using a treeview as a menu, and when the user clicks on a node I want the focus to set to a control (ie textbox) in a panel to the right. The problem I'm having is the focus will not stay on the control, but instead jumps back to the treeview. I'm setting the focus in the AfterSelect event of the treeview, and if I step through...
4
4289
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I have is that sometimes I seem to loose the original "holder" of focus and when the user hits tab while using "temporary" focus(while the mouse is over...
4
67973
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between these forms that may make one succeed and another fail? In particular, this.window.focus() fails in Opera 9.10 with an "object not found", and...
3
7498
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a...
2
7169
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 ToolStrip, each of which has one or more ToolStripButtons.
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7808
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7423
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.