PDA

Click to See Complete Forum and Search --> : [RESOLVED] Double Clicking Blue Part of Form


Fromethius
Mar 28th, 2006, 06:13 PM
Hey guys. Is it possible for when you double click the top of the form, something happens? I mean the blue part.. I have this:


if (e.Location.Y <= 24)
{
MessageBox.Show("Works!");
}


Not really working though.. It also may be good if there was a code for changing what the Maximize Box does. If it is to any help, I am trying to do a rollup. Either when you click the blue part of form or clicking the maximize box, it rolls up and when you click it again, it goes back to the normal size

Thanks!

jmcilhinney
Mar 28th, 2006, 06:24 PM
The title bar of a form is part of the non-client area and you do not have any direct control over it through the .NET Form class. You would have to use APIs to interact with it, like filtering the Windows messages that get sent when the user clicks it. I'd ask in the API forum.

penagate
Mar 28th, 2006, 07:57 PM
What you can do is handle it in the WndProc:

protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXIMIZE = 0xF030;

if (
m.Msg == WM_SYSCOMMAND &&
m.WParam == SC_MAXIMIZE
) {
// do your thing
}
else {
base.WndProc(ref m);
}
}


Now this works for when the user
a) clicks the maximise box, or
b) chooses Maximise from the context menu.

I don't know how to trap the maximise on double click.

penagate
Mar 28th, 2006, 08:06 PM
OK, turns out it's quite simple also :)

Here's the finished code, just insert your rollup routine where the comment is.

protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXIMIZE = 0xF030;
const int SC_MAXIMIZE2 = 0xF032;

if (
m.Msg == WM_SYSCOMMAND &&
(m.WParam.ToInt32() == SC_MAXIMIZE || m.WParam.ToInt32() == SC_MAXMIZE2)
) {
// do your thing
}
else {
base.WndProc(ref m);
}
}

penagate
Mar 28th, 2006, 08:29 PM
That is whole procedure, and that's exactly what it does (also trapping the context menu Maximize option is an unavoidable side effect). It traps the double click on the title bar as well as the click on the maximize box.

I guess you need it for restore as well, so I added that also. Just drop the whole thing as it is into your form code.
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXIMIZE = 0xf030;
const int SC_MAXIMIZE2 = 0xf032;
const int SC_RESTORE = 0xf120;
const int SC_RESTORE2 = 0xf122;

if (
m.Msg == WM_SYSCOMMAND &&
(m.WParam.ToInt32() == SC_MAXIMIZE || m.WParam.ToInt32() == SC_MAXIMIZE2)
) {
// rollup
}
else if (
m.Msg == WM_SYSCOMMAND &&
(m.WParam.ToInt32() == SC_RESTORE || m.WParam.ToInt32() == SC_RESTORE2)
) {
// roll down
}
else {
base.WndProc(ref m);
}
}

Fromethius
Mar 28th, 2006, 09:26 PM
I kinda already had it but thanks anyways:


protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int SC_MAXIMIZE = 0xF030;
const int SC_MAXMIZE2 = 0xF032;

if (
m.Msg == WM_SYSCOMMAND &&
(m.WParam.ToInt32() == SC_MAXIMIZE || m.WParam.ToInt32() == SC_MAXMIZE2)
)
{
if (this.Size == new Size(365, 177))
{
this.Size = new Size(160, 0);
}

else
{
this.Size = new Size(365, 177);
}
}
else
{
base.WndProc(ref m);
}
}

Fromethius
Mar 28th, 2006, 09:29 PM
Also, is there a way to get rid of that little bit left after rolling up? Hold on I'll get some pictures

Fromethius
Mar 28th, 2006, 09:33 PM
This is what I don't want ( Also what I have )

http://server2.uploadit.org/files/Fromethius-dontwant.JPG

This is what I want

http://server2.uploadit.org/files/Fromethius-dowant.JPG


Thanks for all the help so far! :)

penagate
Mar 28th, 2006, 09:43 PM
What you see there is the bottom border, since the form border is part of the non-client area I don't think its possible to remove it without altering the look of the title bar also.

jmcilhinney
Mar 28th, 2006, 09:57 PM
I just read your post more carefully. I assume that you mean replacing the minimise functionality rather than the maximise. Anyway, the ElementsEx library (link in my signature) includes a FormRollup component that does just what you want. It reacts to a double-click on the title bar but you'd have to handle the form being minimised yourself. This works: Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
Me.FormRollup1.SetRolledUp(Me, True)
End If
End Subalthough with a little redundant animation. Note that ElementsEx was compiled for .NET 1.1. I don't know if it will work in .NET 2.0, but they do provide source code so you could recompile if you're using VS 2005 (please specify using the radio buttons provided when creating a new thread). It also won't leave the little bit hanging off the bottom like you mention in your API forum thread.

penagate
Mar 28th, 2006, 10:01 PM
And please don't double post.

395761

Edit: John this is the C# forum not VB :p

jmcilhinney
Mar 28th, 2006, 10:07 PM
And please don't double post.

395761

Edit: John this is the C# forum not VB :pThe double post is my fault really. I thought that there would be a better chance of a relevant answer in API, but I should have also recommended removing the original question and leaving a request for a mod to delete. As for the code... double oops: private void Form1_Resize(object sender, System.EventArgs e) {
if ((this.WindowState == FormWindowState.Minimized)) {
this.WindowState = FormWindowState.Normal;
this.FormRollup1.SetRolledUp(this, true);
}
}Courtesy of one of the translators in my signature.

iPrank
Mar 28th, 2006, 10:13 PM
The API way: :D
protected override void DefWndProc(ref System.Windows.Forms.Message m)
{
const long WM_NCLBUTTONDBLCLK = 163;

if ((long)m.Msg == WM_NCLBUTTONDBLCLK) //We trapped DblClick
{
DialogResult ans;
ans = MessageBox.Show("Discard this message ?","Dblclk", MessageBoxButtons.YesNo);
if (ans==DialogResult.Yes)
{
m.Msg=0; //Discard the message
}
}
//Continue processing the message
base.DefWndProc(ref m);
}

From here (http://www.codeproject.com/Purgatory/MouseClickOnTitlebar.asp). Thanks to SharpDevelop translator. :bigyello:

Fromethius
Mar 29th, 2006, 06:06 AM
Thanks for all your help guys. It works :)

Hack
Mar 29th, 2006, 09:44 AM
And please don't double postYes. Please do not post the same question in two separate threads or two different forums sections.

Thanks.

Duplicate threads merged.