Ejemplo n.º 1
0
        public static void SetRoundedRegion(Form form, Size overrideSize)
        {
            int width, height;

            if (overrideSize == Size.Empty)
            {
                width  = form.ClientSize.Width;
                height = form.ClientSize.Height;
            }
            else
            {
                width  = overrideSize.Width;
                height = overrideSize.Height;
            }

            Region r = new Region(new Rectangle(3, 0, width - 6, height));

            r.Union(new Rectangle(2, 1, width - 4, height - 2));
            r.Union(new Rectangle(1, 2, width - 2, height - 4));
            r.Union(new Rectangle(0, 3, width, height - 6));

            RECT rect = new RECT();

            User32.GetWindowRect(form.Handle, ref rect);
            Point windowScreenPos = RectangleHelper.Convert(rect).Location;
            Point clientScreenPos = form.PointToScreen(new Point(0, 0));

            r.Translate(clientScreenPos.X - windowScreenPos.X, clientScreenPos.Y - windowScreenPos.Y);

            form.Region = r;
        }
Ejemplo n.º 2
0
        public override void Draw(RECT rcBounds, RECT rcUpdate, int lDrawFlags, IntPtr hdc, IntPtr pvDrawObject)
        {
            drawDepth++;
            try
            {
                if (drawDepth > 1)
                {
                    return;
                }

                _HTML_PAINTER_INFO pInfo = new _HTML_PAINTER_INFO();
                GetPainterInfo(ref pInfo);

                //adjust the draw bounds to remove our padding for invalidates
                Rectangle drawBounds = RectangleHelper.Convert(rcBounds);
                drawBounds.X      += invalidationPadding;
                drawBounds.Y      += invalidationPadding;
                drawBounds.Height -= invalidationPadding * 2;
                drawBounds.Width  -= invalidationPadding * 2;

                using (Graphics g = Graphics.FromHdc(hdc))
                {
                    OnDraw(g, drawBounds, rcBounds, rcUpdate, lDrawFlags, hdc, pvDrawObject);
                }
            }
            finally
            {
                drawDepth--;
            }
        }
        private bool IsMouseInFrame()
        {
            RECT rect = new RECT();

            User32.GetWindowRect(_form.Handle, ref rect);
            Rectangle windowRect = RectangleHelper.Convert(rect);

            return
                (windowRect.Contains(Control.MousePosition) &&
                 !_form.ClientRectangle.Contains(_form.PointToClient(Control.MousePosition)));
        }
Ejemplo n.º 4
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // fix up layout
            using (new AutoGrow(this, AnchorStyles.Bottom, false))
            {
                LayoutHelper.NaturalizeHeight(checkBoxViewPost);
            }

            // position form
            RECT parentRect = new RECT();

            User32.GetWindowRect(_parentFrame.Handle, ref parentRect);
            Rectangle parentBounds = RectangleHelper.Convert(parentRect);

            Location = new Point(parentBounds.Left + ((parentBounds.Width - Width) / 2), parentBounds.Top + (int)(1.5 * Height));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Invalidate a rectangular area of the rectangle
 /// </summary>
 /// <param name="rect"></param>
 public void Invalidate(Rectangle rect)
 {
     try
     {
         if (_htmlPaintSite == null)
         {
             return; //avoid exceptions that may occur if invalidates are triggered during initialization
         }
         RECT invalidRect = RectangleHelper.Convert(rect);
         _htmlPaintSite.InvalidateRect(ref invalidRect);
     }
     catch (Exception)
     {
         //TODO: An exception gets thrown here when dragging or deleting images
         //and causes the image behavior to completely break. Is this exception OK to ignore, or
         //is there some protection logic we can put here?
         //Debug.Fail("An exception occurred during invalidate", e.ToString());
     }
 }
        private static void CenterForm(IWin32Window hRelativeToWnd, Form form)
        {
            // if the owning form is not visible then center on the desktop
            if (!User32.IsWindowVisible(hRelativeToWnd.Handle))
            {
                hRelativeToWnd = Win32WindowImpl.DesktopWin32Window;
            }

            // get the coordinates of the relativeToWnd
            RECT rect = new RECT();

            User32.GetWindowRect(hRelativeToWnd.Handle, ref rect);
            Rectangle centerOnRect = RectangleHelper.Convert(rect);

            // determine the center point
            Point centerPoint = new Point(centerOnRect.Left + (centerOnRect.Width / 2), centerOnRect.Top + (centerOnRect.Height / 2));

            // center the form on that point
            form.Location = new Point(centerPoint.X - (form.Width / 2), centerPoint.Y - (form.Height / 2));
        }