-
Mar 28th, 2006, 07:13 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Double Clicking Blue Part of Form
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:
Code:
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!
Last edited by Hack; Mar 29th, 2006 at 10:45 AM.
-
Mar 28th, 2006, 07:24 PM
#2
Re: Double Clicking Blue Part of Form
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.
-
Mar 28th, 2006, 08:57 PM
#3
Re: C# Windows Form Blue Bar
What you can do is handle it in the WndProc:
Code:
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.
-
Mar 28th, 2006, 09:06 PM
#4
Re: C# Windows Form Blue Bar
OK, turns out it's quite simple also
Here's the finished code, just insert your rollup routine where the comment is.
Code:
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);
}
}
-
Mar 28th, 2006, 09:29 PM
#5
Re: C# Windows Form Blue Bar
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.
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);
}
}
-
Mar 28th, 2006, 10:26 PM
#6
Thread Starter
Frenzied Member
Re: C# Windows Form Blue Bar
I kinda already had it but thanks anyways:
Code:
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);
}
}
-
Mar 28th, 2006, 10:29 PM
#7
Thread Starter
Frenzied Member
Re: C# Windows Form Blue Bar
Also, is there a way to get rid of that little bit left after rolling up? Hold on I'll get some pictures
-
Mar 28th, 2006, 10:33 PM
#8
Thread Starter
Frenzied Member
-
Mar 28th, 2006, 10:43 PM
#9
Re: C# Windows Form Blue Bar
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.
-
Mar 28th, 2006, 10:57 PM
#10
Re: Double Clicking Blue Part of Form
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:
VB Code:
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 Sub
although 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.
Last edited by jmcilhinney; Mar 28th, 2006 at 11:00 PM.
-
Mar 28th, 2006, 11:01 PM
#11
Re: Double Clicking Blue Part of Form
And please don't double post.
https://www.vbforums.com/showthread.php?t=395761
Edit: John this is the C# forum not VB
-
Mar 28th, 2006, 11:07 PM
#12
Re: Double Clicking Blue Part of Form
Originally Posted by penagate
The 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:
Code:
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.
-
Mar 28th, 2006, 11:13 PM
#13
Re: Double Clicking Blue Part of Form
The API way:
Code:
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. Thanks to SharpDevelop translator.
-
Mar 29th, 2006, 07:06 AM
#14
Thread Starter
Frenzied Member
Re: Double Clicking Blue Part of Form
Thanks for all your help guys. It works
-
Mar 29th, 2006, 10:44 AM
#15
Re: Double Clicking Blue Part of Form
Originally Posted by penagate
And please don't double post
Yes. Please do not post the same question in two separate threads or two different forums sections.
Thanks.
Duplicate threads merged.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|