c# - Can't resize a borderless winform from top because of a docked panel -


i made borderless windows form, added drop shadow, ability drag, , ability resize angle, here's did, it's little messy:

using system.runtime.interopservices;  public class main {     [dllimport("gdi32.dll", entrypoint = "createroundrectrgn")]     private static extern intptr createroundrectrgn     (         int nleftrect, // x-coordinate of upper-left corner         int ntoprect, // y-coordinate of upper-left corner         int nrightrect, // x-coordinate of lower-right corner         int nbottomrect, // y-coordinate of lower-right corner         int nwidthellipse, // height of ellipse         int nheightellipse // width of ellipse     );     [dllimport("dwmapi.dll")]     public static extern int dwmextendframeintoclientarea(intptr hwnd, ref margins pmarinset);     [dllimport("dwmapi.dll")]     public static extern int dwmsetwindowattribute(intptr hwnd, int attr, ref int attrvalue, int attrsize);     [dllimport("dwmapi.dll")]     public static extern int dwmiscompositionenabled(ref int pfenabled);     private bool m_aeroenabled;                     // variables box shadow     private const int cs_dropshadow = 0x00020000;     private const int wm_ncpaint = 0x0085;     private const int wm_activateapp = 0x001c;     public struct margins                           // struct box shadow     {         public int leftwidth;         public int rightwidth;         public int topheight;         public int bottomheight;     }     private const int wm_nchittest = 0x84;          // variables dragging form     private const int htclient = 0x1;     private const int htcaption = 0x2;     protected override createparams createparams     {                 {             m_aeroenabled = checkaeroenabled();              createparams cp = base.createparams;             if (!m_aeroenabled)                 cp.classstyle |= cs_dropshadow;              return cp;         }     }     private bool checkaeroenabled()     {         if (environment.osversion.version.major >= 6)         {             int enabled = 0;             dwmiscompositionenabled(ref enabled);             return (enabled == 1) ? true : false;         }         return false;     }     protected override void wndproc(ref message m)     {         const int wmnchittest = 0x84;         const int htleft = 10;         const int htright = 11;         const int httop = 12;         const int httopleft = 13;         const int httopright = 14;         const int htbottom = 15;         const int htbottomleft = 16;         const int htbottomright = 17;         bool handled = false;         switch (m.msg)         {             case wm_ncpaint:                        // box shadow                 if (m_aeroenabled)                 {                     var v = 2;                     dwmsetwindowattribute(this.handle, 2, ref v, 4);                     margins margins = new margins()                     {                         bottomheight = 1,                         leftwidth = 1,                         rightwidth = 1,                         topheight = 1                     };                     dwmextendframeintoclientarea(this.handle, ref margins);                  }                 break;             default:                 break;         }         if (m.msg == wmnchittest)         {             int x = (int)(m.lparam.toint64() & 0xffff);             int y = (int)((m.lparam.toint64() & 0xffff0000) >> 16);             point pt = pointtoclient(new point(x, y));             size clientsize = clientsize;             ///allow resize on lower right corner             if (pt.x >= clientsize.width - 16 && pt.y >= clientsize.height - 16 && clientsize.height >= 16)             {                 m.result = (intptr)(ismirrored ? htbottomleft : htbottomright);                 return;             }             ///allow resize on lower left corner             if (pt.x <= 16 && pt.y >= clientsize.height - 16 && clientsize.height >= 16)             {                 m.result = (intptr)(ismirrored ? htbottomright : htbottomleft);                 return;             }             ///allow resize on upper right corner             if (pt.x <= 16 && pt.y <= 16 && clientsize.height >= 16)             {                 m.result = (intptr)(ismirrored ? httopright : httopleft);                 return;             }             ///allow resize on upper left corner             if (pt.x >= clientsize.width - 16 && pt.y <= 16 && clientsize.height >= 16)             {                 m.result = (intptr)(ismirrored ? httopleft : httopright);                 return;             }             ///allow resize on top border             if (pt.y <= 16 && clientsize.height >= 16)             {                 m.result = (intptr)(httop);                 return;             }             ///allow resize on bottom border             if (pt.y >= clientsize.height - 16 && clientsize.height >= 16)             {                 m.result = (intptr)(htbottom);                 return;             }             ///allow resize on left border             if (pt.x <= 16 && clientsize.height >= 16)             {                 m.result = (intptr)(htleft);                 return;             }             ///allow resize on right border             if (pt.x >= clientsize.width - 16 && clientsize.height >= 16)             {                 m.result = (intptr)(htright);                 return;             }         }         if (!handled)             base.wndproc(ref m);     }     public main()     {         initializecomponent();         m_aeroenabled = false;     }     private point mmousepos;     private point mformpos;     private bool mdragging;     private void header_mousedown(object sender, mouseeventargs e)     {         mdragging = true;         mmousepos = header.pointtoscreen(e.location);         mformpos = location;      }      private void header_mouseup(object sender, mouseeventargs e)     {         mdragging = false;          }     private void header_mousemove(object sender, mouseeventargs e)     {         if (!mdragging) return;         point pos = header.pointtoscreen(e.location);         left = mformpos.x + pos.x - mmousepos.x;         top = mformpos.y + pos.y - mmousepos.y;     } } 

main form's name, while header name of panel, problem have trying resize top, because panel docked, want put code in class , call whenever create new form. massively appreciated.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -