Results 1 to 15 of 15

Thread: [RESOLVED] Double Clicking Blue Part of Form

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Resolved [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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);
          }
        }

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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);
          }
        }

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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);
                }
            }

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: C# Windows Form Blue Bar

    This is what I don't want ( Also what I have )



    This is what I want




    Thanks for all the help so far!

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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:
    1. Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    2.         If Me.WindowState = FormWindowState.Minimized Then
    3.             Me.WindowState = FormWindowState.Normal
    4.             Me.FormRollup1.SetRolledUp(Me, True)
    5.         End If
    6.     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.

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Double Clicking Blue Part of Form

    Quote Originally Posted by penagate
    And please don't double post.

    https://www.vbforums.com/showthread.php?t=395761

    Edit: John this is the C# forum not VB
    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.

  13. #13
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Double Clicking Blue Part of Form

    Thanks for all your help guys. It works

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Double Clicking Blue Part of Form

    Quote 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
  •  



Click Here to Expand Forum to Full Width