Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:41:57+00:00 2026-06-18T02:41:57+00:00

I am using a borderless form and implemented the form with HTCAPTION so that

  • 0

I am using a borderless form and implemented the form with HTCAPTION so that it can be dragged around. Another benefit of HTCAPTION is that when doubled cliked, it can minimize and maximize. The only problem is that I want to catch an event so that when the window is maximized, I can change the icon of a button from maximize button to normal mode button.
Any great ideas on how to implement this?

protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

        switch(m.Msg)
        {
            case Global.WM_NCHITTEST:
                Point mouseCursor = PointToClient(Cursor.Position);

                if (mouseCursor.X < borderSize && mouseCursor.Y < borderSize)
                    m.Result = (IntPtr)Global.HTTOPLEFT;
                else if (mouseCursor.X < borderSize && mouseCursor.Y > Height - borderSize)
                    m.Result = (IntPtr)Global.HTBOTTOMLEFT;
                else if (mouseCursor.X < borderSize)
                    m.Result = (IntPtr)Global.HTLEFT;
                else if (mouseCursor.X > Width - borderSize && mouseCursor.Y < borderSize)
                    m.Result = (IntPtr)Global.HTTOPRIGHT;
                else if (mouseCursor.X > Width - borderSize && mouseCursor.Y > Height - borderSize)
                    m.Result = (IntPtr)Global.HTBOTTOMRIGHT;
                else if (mouseCursor.X > Width - borderSize)
                    m.Result = (IntPtr)Global.HTRIGHT;
                else if (mouseCursor.Y < borderSize)
                    m.Result = (IntPtr)Global.HTTOP;
                else if (mouseCursor.Y > Height - borderSize)
                    m.Result = (IntPtr)Global.HTBOTTOM;
                else
                    m.Result = (IntPtr)Global.HTCAPTION;
                break;
        }
    }

This is the code I want to add in the catched event

        if (WindowState == FormWindowState.Maximized)
        {
            WindowState = FormWindowState.Normal;
            pb_max.Image = GomeeSoft.Properties.Resources.buttonmax;
        }
        else
        {
            Screen screen = Screen.FromRectangle(new Rectangle(Left, Top, Width, Height));
            this.MaximumSize = screen.WorkingArea.Size;
            WindowState = FormWindowState.Maximized;
            pb_max.Image = GomeeSoft.Properties.Resources.buttonreturn;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:41:59+00:00Added an answer on June 18, 2026 at 2:41 am

    Double-clicking generates WM_SYSCOMMAND messages. Which you can detect with WndProc as well:

        private const int WM_NCHITTEST = 0x84;
        private const int WM_SYSCOMMAND = 0x112;
        private const int SC_MINIMIZE = 0xf020;
        private const int SC_MAXIMIZE = 0xf030;
        private const int SC_RESTORE = 0xf120;
    
        protected override void WndProc(ref Message m) {
            if (m.Msg == WM_SYSCOMMAND) {
                switch (m.WParam.ToInt32() & 0xfff0) {
                    case SC_MINIMIZE: Console.WriteLine("Minimize"); break;
                    case SC_MAXIMIZE: Console.WriteLine("Maximize"); break;
                    case SC_RESTORE:  Console.WriteLine("Restore");  break;
                }
            }
            base.WndProc(ref m);
            if (m.Msg == WM_NCHITTEST && m.Result == (IntPtr)1) m.Result = (IntPtr)2;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that lets be drag around a borderless form in winforms that
I am trying to make a form borderless which can be resized and dragged.
I am using a transparent borderless WPF window to get around some drawing limitations
Using CRM 4, I have an entity form that contains a tab with an
I'm trying to create a borderless form with custom close and minimize button. However
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
I have a borderless NSButton that contains an image and is subclassed with my
I'd like to create a custom window using WPF that doesn't look like the
I am trying to do a very minimalistic sample of borderless video using swfobject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.