EEssam
asked on
An issue with TopMost property
Hi,
I have the TopMost property set to true for a form, and it works... but I don't want the form to be "TopMost" when moved over the taskbar. I want it TopMost everything, except when touching the taskbar it should act as normal form and have the part that is touching the taskbar go behind it.
Please help. Thanks.
I have the TopMost property set to true for a form, and it works... but I don't want the form to be "TopMost" when moved over the taskbar. I want it TopMost everything, except when touching the taskbar it should act as normal form and have the part that is touching the taskbar go behind it.
Please help. Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
public static void CheckAutFocus(IntPtr hWnd)
{
if (GetForegroundWindow() != hWnd)
{
SetForegroundWindow(hWnd);
}
}
// You can add this on the form shown event
ASKER
How can I activate the code in Form1_Load for example?
Thanks.
Thanks.
You just simply add the method call : CheckAutFocus(this.Handle) ;
Regards,
Mishu
Regards,
Mishu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The code attached is not doing the trick. Please check it.
Agarici,
Thanks a lot for the magnet effect. I've been looking for it for longtime!
Agarici,
Thanks a lot for the magnet effect. I've been looking for it for longtime!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CheckAutFocus(this.Handle);
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
public static void CheckAutFocus(IntPtr hWnd)
{
if (GetForegroundWindow() != hWnd)
{
SetForegroundWindow(hWnd);
}
}
}
}
ASKER
The code is broken. Please test it.