Double Click in titlebar

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

does anyone have any idea how to trap a double click event in the title
bar of a form?

I'm wanting to use help icons on titlebars, but this means that I can't
have minimize or maximize buttons, and as a compromise I wish to enable
a double click on the title bar to either minimize or maximize the
form, which is doesn't do if you have a help icon!

I've googled for ages but to no avail - the closest example I have
found is in VB at
http://www.codeproject.com/Pur gatory/MouseClickOnTitlebar.as p but I
need something similar in C# and for a double click,

any help would be much appreciated!

Stu
 
Stu,

Override your form's WndProc method. The following code should lead you
along the right path...

protected override void WndProc(ref Message m)
{
//WM_LBUTTONDBLCLK
if (m.Msg == 0x0203)
{

}

base.WndProc (ref m);
}
 
Johann Blake said:
Stu,

Override your form's WndProc method. The following code should lead you
along the right path...

protected override void WndProc(ref Message m)
{
//WM_LBUTTONDBLCLK
if (m.Msg == 0x0203)
{

}

base.WndProc (ref m);
}

To trap a double click in the title bar I think you need to handle the
WM_NCLBUTTONDBLCLK message (value 0x00A3) rather than WM_LBUTTONDBLCLK.

Chris Jobson
 
Thankyou! This is how I've done it, it's pretty hacky because when the form
is in the maximised state the double click event in the title bar is fired
and the form gets minimized automatically, so I've had to use a flag to say
when I've fired my own maximize

private bool m_bSelfMaximiseFlag = false;
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == 0x00A3)
{
if((this.WindowState==FormWindowState.Normal)&&(!m_bSelfMaximiseFlag))
{
this.WindowState=FormWindowState.Maximized;
m_bSelfMaximiseFlag = true;
}
else
{
m_bSelfMaximiseFlag = false;
}
}
}
 
Back
Top