Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

An issue with TopMost property

Posted on 2007-11-23
8
Medium Priority
?
548 Views
Last Modified: 2013-12-16
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.
0
Comment
Question by:EEssam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 11

Assisted Solution

by:Agarici
Agarici earned 800 total points
ID: 20340001
i dont think you can do that. not using topmost property.
0
 
LVL 11

Assisted Solution

by:Mihai Stancescu
Mihai Stancescu earned 200 total points
ID: 20365481
Try instead of TopMost = true SetForegroundWindow API method.

This link will show you how to declare it, and how to use it.
http://pinvoke.net/default.aspx/user32/SetForegroundWindow.html

Hope it helps!

Regards,
Mishu
0
 

Author Comment

by:EEssam
ID: 20367089
Mishu007,

The code is broken. Please test it.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Expert Comment

by:Mihai Stancescu
ID: 20367516
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

Open in new window

0
 

Author Comment

by:EEssam
ID: 20376944
How can I activate the code in Form1_Load for example?

Thanks.
0
 
LVL 11

Expert Comment

by:Mihai Stancescu
ID: 20380194
You just simply add the method call : CheckAutFocus(this.Handle);

Regards,
Mishu
0
 
LVL 11

Accepted Solution

by:
Agarici earned 800 total points
ID: 20380616
unfortunatelly this will not be the same as topmost property
it will only be in effect until the user clicks on an other window or does alt-tab

i think what you can do is the folowing:
overwrite the WndProc method, and do some trick when you receive WM_WINDOWPOSCHANGING
http://msdn2.microsoft.com/en-us/library/ms632653.aspx
maybe this can help:
http://www.codeproject.com/vb/net/SnapForm.asp?df=100&forumid=335272&exp=0&select=2310934

hth,
A
0
 

Author Comment

by:EEssam
ID: 20389577
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!
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);
            }
        }
 
    }
}

Open in new window

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question