Solved

An issue with TopMost property

Posted on 2007-11-23
8
535 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
  • 3
  • 3
  • 2
8 Comments
 
LVL 11

Assisted Solution

by:Agarici
Agarici earned 400 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 100 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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 400 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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