Esempio n. 1
0
            internal void SetBorder(TBBorder value)
            {
                int _Pad(TBBorder b) => b >= TBBorder.Width2 && b <= TBBorder.Width4 ? (int)b - 1 : 0;

#if true
                int pOld = _Pad(_tb._border), pNew = _Pad(value), pDif = pNew - pOld;
                if (pDif != 0)
                {
                    this.Padding = new Padding(pNew);
                }
                var w = this.Hwnd();
                if (!w.Is0)
                {
                    RECT     r = w.ClientRectInScreen; r.Inflate(pDif, pDif); r.Normalize(false);
                    const WS mask = WS.CAPTION | WS.THICKFRAME | WS.SYSMENU;
                    WS       s1 = w.Style, s2 = _BorderStyle(value);
                    if (s2 != (s1 & mask))
                    {
                        w.SetStyle((s1 & ~mask) | s2);
                    }
                    //preserve client size and position
                    Api.AdjustWindowRectEx(ref r, _BorderStyle(value), false, WS2.TOOLWINDOW);
                    w.MoveLL(r.left, r.top, r.Width, r.Height, Native.SWP.FRAMECHANGED);
                }
#else //this simpler code does not preserve client size and position
                int pOld = _Pad(_tb._border), pNew = _Pad(value);
                if (pNew != pOld)
                {
                    this.Padding = new Padding(pNew);
                }
                var w = this.Hwnd();
                if (!w.Is0)
                {
                    const WS mask = WS.CAPTION | WS.THICKFRAME | WS.SYSMENU;
                    WS       s1 = w.Style, s2 = _BorderStyle(value);
                    if (s2 != (s1 & mask))
                    {
                        w.SetStyle((s1 & ~mask) | s2, updateNC: true, updateClient: true);
                    }
                }
#endif
            }
Esempio n. 2
0
 WS _BorderStyle(TBBorder b) => b switch
 {