Good Evening. I'm building a C# application, as follows : a main frame that allows the user to popup sub-forms, each one containing a WebBrowser component that loads a flash animation.

The problem is the following: whenever i simulate a click on the subforms, they popup in the foreground and hide the main Form , while I need them to stay exactly where they are. How can I accomplish that? I've tried using the following code :

private const int WM_MOUSEACTIVATE = 0x0021; 
private const int MA_NOACTIVATE = 3;       
protected override void WndProc(ref Message m)       
{
            if (m.Msg == WM_MOUSEACTIVATE)
            {
                m.Result = (IntPtr)MA_NOACTIVATE;
                return;
            }
            base.WndProc(ref m);       
}

without success.

Thanks for your help

Your question isn't very clear.

  • Do you want to be able to controle all the sub forms from the main form?
  • Do you want to be able to open more than one sub form at a time?

Do you have any more code than above to show us more of what you have done so far?

The problem is not what controls what. I just need the form to stay where they are ( in the background for instance) when i simulate a click on them with PostMessage.
Think of something like a main form containing a video list, and once the user clicks on an element, a new form is opened containing a flash video player. Now, what i need is, at some point, to pause one of the videos in the background in an automatic manner, without popping up in front of the one the user is watching.
I'd post some code, but there's not really anything peculiar in it...

Thanks for your reply :) at the moment I managed to do something similar to what i need with

[DllImportAttribute("user32.dll", EntryPoint = "SetForegroundWindow")]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow([InAttribute()] IntPtr hWnd);

[DllImportAttribute("user32.dll", EntryPoint = "GetForegroundWindow")]
public static extern IntPtr GetForegroundWindow();

[DllImportAttribute("user32.dll", EntryPoint = "BringWindowToTop")]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern bool BringWindowToTop([InAttribute()] IntPtr hWnd);

IntPtr old = GetForegroundWindow();
LeftClick(hw, x, y);
SetForegroundWindow(old);
BringWindowToTop(old);

The downside is, the "clicked" form still pops up for a graction of second, giving a bad style effect. Any other hint that helps keeping the form in the background is wellcome :)

Hi Kaharas, sorry it's taken me so long for something that is pretty simple but I honestly didn't know how to do this myself, I guess we really do learn something new everyday.

In the initilizer method for your main form use:

this.TopMost = true;

This will set your main form to always be on top of all other forms. However other forms will appear behind this form so you may need to either move the main form after opening a child form, or set the position for the form to open.

Edited 4 Years Ago by ChrisHunter: Grammer changes

The problem is, I don't want the main form to be on top, but just have the childs keep their order :) Let's say that forms are stacked, and we have Form1 > Form2 > Form3. Now, if I simulate a click on Form3, the order will become Form3 > Form1 > Form2, while I them to keep their original order, that is, Form1 > Form2 > Form3. I don't really care if Form1 is the Main form, or just another Child, what I do care is for the order to be preserved.

That does't make much sence, you want to simulate a click on form3 (so click on form3) but you want the click to be registered on form1 first, followed by form 2 and finnally something happends on form3 ?

I've been trying to play with the focus properties of forms but i'm at a loss at the moment. could you clear up the above please ?

mmm ... It's quite hard for me to be more clear than that, but I'll give it a try :)
You have the usual 3 stacked forms, Form1 on top, Form2 in the middle, and Form3 at the botton. What I need to do is to simulate a click on Form3, without it popping in front of Form1 or Form 2, or to simulate a click on Form2 without it popping up in front of Form1.

This article has been dead for over six months. Start a new discussion instead.