Solved

An issue with TopMost property

Posted on 2007-11-23
8
527 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now