TopMost without setting the form to be in top of all operating windows
Hi,
I have an application which has a form which does the Loading Dialog so the user knows there is something loading in the background and so the user cant close or touch the running form or windows.
Now say I have Microsoft Word open and then I open my application and I log in the application, the Loading Dialog will show and I have set the property of the form TopMost = true. But I have found that what it does it to show this form in top of all windows so if I try to open Microsoft Word I have the Loading bar in top and I can't read what it's in the page.
I have set the property to Top Most so the user can see that there is something loading in top of my application. But badly it also goes in top of other applications.
Is there any way to solve this?
Kirtan PatelPosted Oct 26, 2009, 7:23 AM
Below is Perfect Solution For you :)
regorPosted Oct 26, 2009, 7:54 AM
regorPosted Oct 26, 2009, 4:55 AM
theLizardPosted Oct 23, 2009, 6:37 PM
If you just want your form to be in front of all your other forms in your application while it is doing work, try using
this.BringToFront();
To keep it in front while your form is doing work, try a timer control and this code in its Tick event
while(this.Visible){ //as long as the form is visible (doing work) execute the following code.
Application.DoEvents(); //give windows a chance to process other messages
this.BringToFront(); //bring the form to the top of your application
this.Focus(); //set the focus to your form
}
Kirtan PatelPosted Oct 23, 2009, 9:08 AM
please check "Do you like this answer" if it helps you :)
using System.Runtime.InteropServices;
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,int Y, int cx, int cy, uint uFlags);
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
static readonly IntPtr HWND_TOP = new IntPtr(0);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, this.Height, this.Width, TOPMOST_FLAGS);
}
}
Here Another Code too That is Simply but its window will top of All Except System Alerts