views:

34

answers:

1

Any suggestions on how to create a Photoshop style floating tool palette? I've tried several ideas such as:

  1. Creating a child window, setting its FormBorderStyle to FixedToolWindow and showing it as a child of the main form, but the tool window steals focus from the main form.
  2. Creating a child window as above and using various combinations of flags passed to CreateParams but still run into the same focus issues.
  3. Creating the tool palette as a UserControl and and "floating it" by setting its parent to be the desktop (via the user32#SetParent function), but then it's no longer a child of the main form and does not minimize/restore with the main form.

I'm thinking #3 is the way to go and I'm going to have to write the code to keep the tool palette window state in sync with the main form as well as implement the ability to drag the palette around, draw borders, etc...

Suggestions on better ways to tackle this?

A: 

I'm only aware of one way to do this, but it limits you to child forms that can't leave the parent form like the ones in Photoshop can. Override CreateParams on the child form:

const int WS_EX_NOACTIVATE = 0x8000000;
const int WS_CHILD = 0x40000000;
protected override CreateParams CreateParams
{
    get
    {
        CreateParams ret = base.CreateParams;
        ret.Style |= WS_CHILD;
        ret.ExStyle |= WS_EX_NOACTIVATE;
        return ret;
    }
}

Make sure that when you call Show on the child form, you use the overload that takes an IWin32Window and pass in the parent.

allonym