Results 1 to 4 of 4

Thread: [2.0] Custom border form problem (Advanced. Guru needed)

  1. #1

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    [2.0] Custom border form problem (Advanced. Guru needed)

    I'm having a problem processing the WM_NCCALCSIZE message to redefine the border widths of a form.

    This is the code:

    Code:
        private void WmNCCalcSize(ref Message m)
        {
          if (m.WParam.ToInt32() == 0)
          {
            RECT rc = (RECT)m.GetLParam(typeof(RECT));
            rc.Left += 120;
            rc.Top += 20;
            rc.Right -= 20;
            rc.Bottom -= 20;
            Marshal.StructureToPtr(rc, m.LParam, true);
            m.Result = IntPtr.Zero;
          }
          else
          {
            NCCALCSIZE_PARAMS csp;
            csp = (NCCALCSIZE_PARAMS)m.GetLParam(typeof(NCCALCSIZE_PARAMS));
            csp.rgrc0.Top += 120;
            csp.rgrc0.Bottom -= 20;
            csp.rgrc0.Left += 20;
            csp.rgrc0.Right -= 20;
            Marshal.StructureToPtr(csp, m.LParam, true);
            //Return zero to preserve client rectangle
            m.Result = IntPtr.Zero;
          }
        }
    Works perfectly - that is until the user maximizes and normalizes the form, then the size of the @#!##@% form changes! i.e. it does not restore to the proper size.

    It's driving me nuts.

    A small and rather messy project illustrating the problem is attached. Sorry, it's a rar as I don't have WinZip on this machine.

    Any ideas? Can it be a DotNet bug?

    Help!!!!
    Attached Files Attached Files
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: [2.0] Custom border form problem (Advanced. Guru needed)

    Well, I'm no guru, but I think I know what the problem is. The overriden WndProc function's switch statement doesn't take into account that WM_WINDOWPOSCHANGED sets the client rectangle (Effectively calling that function you posted twice).. if you choose to simply ignore that message, the thing works fine.. i.e,

    add this to your switch statement

    Code:
          case (int)NativeMethods.WindowMessages.WM_WINDOWPOSCHANGED: break;

    hth,

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Re: [2.0] Custom border form problem (Advanced. Guru needed)

    That sounds logical. I'll give it a try.

    Many thanks Bill!
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  4. #4

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Re: [2.0] Custom border form problem (Advanced. Guru needed)

    Hi Bill.

    Yes, that did the trick. Thanks!
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

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