How to make a floating ToolWindow transparent?

Docking/MDI for Windows Forms Forum

Posted 18 years ago by Gerard Laslett
Avatar
I need to make a ActiproSoftware.UIStudio.Dock.ToolWindow transparent when floating...

Just like you do with a System.Windows.Forms.Form in the code:
this.Opacity = 80.0F;

This is for floating tools in an application...

How do I do this?

Comments (7)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We don't currently have a property to set the transparency directly but I can add it to the TODO list for you. Also you can get it working right now manually by adding this code after you activate the tool window:
toolWindow.FindForm().Opacity = .8f;


Actipro Software Support

Posted 18 years ago by Gerard Laslett
Avatar
ok - thanks, yeah - I did that, and it worked.

However - I was also trying to pick up the mouse events for the form that I normally do when making a tool with a normal windows form... and it seems the host form isn't picking up most of the events I needed...
Form hostForm = toolWindow.FindForm();
hostForm.MouseEnter += new EventHandler(hostForm_MouseEnter);
hostForm.MouseLeave += new EventHandler(hostForm_MouseLeave);
MouseEnter & MouseLeave where never fired

however...
hostForm.Activated += new EventHandler(hostForm_Activated);
hostForm.Deactivate += new EventHandler(hostForm_Deactivate);
Activated & Deactivate worked as expected.

PS: I'm doing something like this in the handlers
void hostForm_Enter(object sender, EventArgs e)
{
    Form f = (Form)sender;
    f.Opacity = 1.0F;
}
void hostForm_Leave(object sender, EventArgs e)
{
    if (_isActivated) return;
    Form f = (Form)sender;
    f.Opacity = 0.80F;
}
Any thoughts?

cheers.

[Modified at 06/14/2006 09:17 AM]

[Modified at 06/14/2006 09:17 AM]
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ahh so you want the Form to be semi-transparent unless it has focus or the mouse is over it. Neat idea.

It might be that the ToolWindow fills the Form and therefore the mouse is never over the client area of the Form. Maybe try to attach to the MouseEnter and MouseLeave of the ToolWindow instead.


Actipro Software Support

Posted 18 years ago by Gerard Laslett
Avatar
Yes - I had already attempted what you suggested without any luck.

Basically - what I need to do is the following (shown by using System.Windows.Forms.Form instead)
private void Form1_Load(object sender, EventArgs e)
        {
            ToolForm f = new ToolForm();
            f.MouseEnter += new EventHandler(f_MouseEnter);
            f.MouseLeave += new EventHandler(f_MouseLeave);
            f.Activated += new EventHandler(f_Activated);
            f.Deactivate += new EventHandler(f_Deactivate);
            f.TopMost = true;
            f.Show();
            
        }

        bool _activated = false;

        void f_Deactivate(object sender, EventArgs e)
        {
            ((Form)sender).Opacity = 0.8F;
            _activated = false;
        }

        void f_Activated(object sender, EventArgs e)
        {
            ((Form)sender).Opacity = 1.0F;
            _activated = true;
        }

        void f_MouseLeave(object sender, EventArgs e)
        {
            if (_activated) return; // if activated, keep the opacity until de-activation
            ((Form)sender).Opacity = 0.8F;
        }

        void f_MouseEnter(object sender, EventArgs e)
        {
            ((Form)sender).Opacity = 1.0F;
        }
...where, ToolForm is just a standard Form with control etc on it.

I tried the following code as you suggested...
toolWindow.MouseEnter+=new EventHandler(toolWindow_MouseEnter);

but the event wasn't hooked.

I'm wondering if some code inside the ToolWindow creates a Form derived object, and that the Form derived object overrides OnMouseEnter and doesn't pass control back to the base implementation allowing the event to fire.

I'll check with Reflector and in the debugger tomorrow...
Posted 18 years ago by Gerard Laslett
Avatar
Oh.. I'm also using UIStudio 1.5

Is that going to make a significant difference with stuff like this?
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The v1.5 dock controls are very similar to v2.0 so that shouldn't matter. I think it's Windows Forms behavior that the mouse events only fire for the Control that the mouse is over. So if you have another control Fill docked within the tool window then that is probably the control you need to attach the mouse events too.

Stuff like this makes it difficult to design docking controls in the first place since sometimes events don't fire when you expect them to. That's why a lot of times we have to do a mouse hook instead to track where the mouse is like for auto-hide, etc.


Actipro Software Support

Posted 18 years ago by Gerard Laslett
Avatar
Ah - true.
Thanks for your help.
The latest build of this product (v24.1.0) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.