Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

An issue with TopMost property

Posted on 2007-11-23
8
Medium Priority
?
552 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

971 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