Exemplo n.º 1
0
        private void loadStructure(Vector2 position, string structureID)
        {
            elements = new List <Tuple <Rectangle, Vector2, string> >();
            bounds   = new List <RectangleF>();
            string    path = AppDomain.CurrentDomain.BaseDirectory + @"Content\structures\" + structureID + ".xml";
            XDocument doc  = XDocument.Load(path);                                            //open xml file

            foreach (XElement element in doc.Descendants("Structure").Descendants("Element")) //Go through each element of structure
            {
                //load rectangle and position from array
                Rectangle rect = RectangleEx.FromArray(element.Element("Rectangle").Value.Split(','));
                Vector2   pos  = VectorEx.FromArray(element.Element("Position").Value.Split(','));

                string sheetID = element.Element("spritesheet").Value;
                if (spritesheets.Count(s => s.SpritesheetID == sheetID) == 0)                //if preloaded sheets don't have necessary spritesheet
                {
                    spritesheets.Add(new Spritesheet(sheetID));
                }
                elements.Add(new Tuple <Rectangle, Vector2, string>(rect, pos, sheetID));
            }
            foreach (XElement element in doc.Descendants("Structure").Descendants("Bounds").Elements("Box"))
            {
                RectangleF boundary = RectangleF.FromArray(element.Value.Split(','));
                boundary.Location += position;
                bounds.Add(boundary);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 渲染标签样式分组控件背景色
        /// </summary>
        /// <param name="rect">渲染区域</param>
        /// <param name="tabSize">左上角标签大小</param>
        /// <param name="tabRound">标签右上角是否发圆角</param>
        /// <param name="tabRadius">标签右上角圆角半径</param>
        public void RenderBackColorGroupBoxTab(Rectangle rect, Size tabSize, bool tabRound, float tabRadius)
        {
            this.m_BackColorRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackColorRect))
            {
                return;
            }

            using (Brush brush = RenderEngine.CreateBrush(this.CurrentBackColorBrushRect, this.CurrentBackColor, this.m_BackColorPos1, this.m_BackColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_BackColorBlendStyle))
            {
                //校正背景区域
                if (this.m_InnerBorderVisibleStyle != BorderVisibleStyle.None)
                {
                    tabSize.Width -= 4;
                }
                else if (this.m_BorderVisibleStyle != BorderVisibleStyle.None)
                {
                    tabSize.Width -= 2;
                }
                using (GraphicsPath path = RenderEngine.CreateGroupBoxTabGraphicsPath(this.CurrentBackColorPathRect, this.m_RoundStyle, this.m_RoundRadius, tabSize, tabRound, tabRadius, false))
                {
                    this.m_Graphics.SetClip(path, CombineMode.Intersect);
                    this.m_Graphics.FillPath(brush, path);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 渲染控件
        /// </summary>
        /// <param name="e">数据</param>
        protected override void RenderSelf(PaintEventArgs e)
        {
            //准备
            Graphics  g    = e.Graphics;
            Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding);

            //渲染
            this.Sprite.BorderVisibleStyle = BorderVisibleStyle.None;
            this.Sprite.BackColor          = this.BackColor;
            this.Sprite.BackColorHovered   = this.HoveredBackColor;
            this.Sprite.BackColorPressed   = this.PressedBackColor;
            this.Sprite.Image             = this.Image;
            this.Sprite.ImageHovered      = this.ImageHovered;
            this.Sprite.ImagePressed      = this.ImagePressed;
            this.Sprite.ImageDisabled     = this.ImageDisabled;
            this.Sprite.ImageSize         = this.ImageSize;
            this.Sprite.ImageAlign        = this.ImageAlign;
            this.Sprite.Font              = this.Font;
            this.Sprite.ForeColor         = this.ForeColor;
            this.Sprite.ForeColorHovered  = this.ForeColor;
            this.Sprite.ForeColorPressed  = this.ForeColor;
            this.Sprite.ForeColorDisabled = this.ForeColor;
            this.Sprite.Text              = this.Text;
            this.Sprite.TextRenderingHint = this.TextRenderingHint;
            this.Sprite.TextAlign         = this.TextAlign;
            this.Sprite.TextImageRelation = this.TextImageRelation;
            this.Sprite.State             = this.State;
            this.Sprite.BeginRender(g);
            this.Sprite.RenderBackColor(rect);
            this.Sprite.RenderTextAndImage(rect);
            this.Sprite.EndRender();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 渲染图片
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderImage(Rectangle rect)
        {
            this.m_TextImageRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_TextImageRect) || this.CurrentImage == null)
            {
                return;
            }

            using (LayoutData layout = new LayoutData())
            {
                layout.Graphics = this.m_Graphics;

                layout.ClientRectangle   = this.CurrentTextImageClientRect;
                layout.Padding           = this.m_Padding;
                layout.TextImageRelation = this.m_TextImageRelation;
                layout.RightToLeft       = this.m_RightToLeft;

                layout.ImageSize   = (this.CurrentImage == null ? Size.Empty : this.m_ImageSize);
                layout.ImageAlign  = this.m_ImageAlign;
                layout.ImageOffset = this.m_ImageOffset;

                this.RenderImageCore(layout);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 渲染控件
        /// </summary>
        /// <param name="e">数据</param>
        protected override void RenderSelf(PaintEventArgs e)
        {
            //准备
            Graphics  g    = e.Graphics;
            Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
            //计算起点终点
            Point begin, end;

            if (this.Horizontal)
            {
                begin = new Point(rect.X, (rect.Y + rect.Bottom) / 2);
                end   = new Point(rect.Right, begin.Y);
            }
            else
            {
                begin = new Point((rect.X + rect.Right) / 2, rect.Y);
                end   = new Point(begin.X, rect.Bottom);
            }
            //渲染
            this.Sprite.LineWidth      = this.LineWidth;
            this.Sprite.LineColor      = this.LineColor;
            this.Sprite.LineBlendStyle = this.LineBlendStyle;
            this.Sprite.LineDashStyle  = this.LineDashStyle;
            base.Sprite.BeginRender(g);
            base.Sprite.RenderLine(begin, end);
            base.Sprite.EndRender();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 渲染文本
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderText(Rectangle rect)
        {
            this.m_TextImageRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_TextImageRect) || this.Text == null || this.Text.Length <= 0)
            {
                return;
            }

            using (LayoutData layout = new LayoutData())
            {
                layout.Graphics = this.m_Graphics;

                layout.ClientRectangle   = this.CurrentTextImageClientRect;
                layout.Padding           = this.m_Padding;
                layout.TextImageRelation = this.m_TextImageRelation;
                layout.RightToLeft       = this.m_RightToLeft;

                layout.Text       = this.m_Text;
                layout.Font       = this.m_Font;
                layout.TextAlign  = this.m_TextAlign;
                layout.TextOffset = this.m_TextOffset;

                this.RenderTextCore(layout);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 渲染控件
        /// </summary>
        /// <param name="e">数据</param>
        protected override void RenderSelf(PaintEventArgs e)
        {
            //准备
            Graphics  g    = e.Graphics;
            Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
            //已完成进度
            int       maxWidth   = rect.Width - 2;
            int       width      = (int)(maxWidth * this.m_Animation.Current / 100d);
            Rectangle rcProgress = new Rectangle(rect.Left + 1, rect.Top + 1, Math.Min(width, maxWidth), rect.Height - 2);
            //未完成进度
            Rectangle rcBlank = new Rectangle(rcProgress.Right, rcProgress.Top, rect.Width - 2 - rcProgress.Width, rcProgress.Height);

            //渲染已完成进度
            this.Sprite.BorderVisibleStyle = BorderVisibleStyle.None;
            this.Sprite.BackColor          = this.ProgressColor;
            this.Sprite.State = this.State;
            this.Sprite.BeginRender(g);
            this.Sprite.RenderBackColor(rcProgress);
            this.Sprite.EndRender();
            //渲染未完成进度
            this.Sprite.BackColor = this.BackColor;
            this.Sprite.BeginRender(g);
            this.Sprite.RenderBackColor(rcBlank);
            this.Sprite.EndRender();
            //渲染边框
            this.Sprite.BorderVisibleStyle = BorderVisibleStyle.All;
            this.Sprite.BorderColor        = this.BorderColor;
            this.Sprite.BeginRender(g);
            this.Sprite.RenderBorder(rect);
            this.Sprite.EndRender();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 渲染箭头(固定大小)
        /// </summary>
        /// <param name="rect">渲染区域</param>
        /// <param name="direction">箭头方向</param>
        /// <param name="style">大小样式</param>
        public void RenderArrow(Rectangle rect, ArrowDirection direction, SizeStyle style)
        {
            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
            {
                return;
            }

            this.CurrentTextPreferredRect = rect;
            RenderEngine.DrawArrow(this.m_Graphics, this.CurrentTextPreferredRect, this.CurrentForeColor, direction, style);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 渲染省略号(按比例渲染)
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderEllipsis(Rectangle rect)
        {
            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
            {
                return;
            }

            this.CurrentTextPreferredRect = rect;
            RenderEngine.DrawEllipsis(this.m_Graphics, this.CurrentTextPreferredRect, this.CurrentForeColor);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 重置动画参数
        /// </summary>
        protected virtual void ResetAnimation()
        {
            Rectangle rect      = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
            Rectangle rcContent = RectangleEx.Subtract(rect, new Padding(1));
            int       width     = rcContent.Width;

            this.m_Animation.From     = rcContent.Left;
            this.m_ProgressLengthReal = (int)(width * this.m_ProgressLength);
            this.m_Animation.To       = width + this.m_ProgressLengthReal + 1;//要多一个像素
        }
Exemplo n.º 11
0
        /// <summary>
        /// 渲染控件
        /// </summary>
        /// <param name="e">数据</param>
        protected override void RenderSelf(PaintEventArgs e)
        {
            //准备
            Graphics  g         = e.Graphics;
            Rectangle rect      = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
            Rectangle rcContent = RectangleEx.Subtract(rect, new Padding(1));

            int left     = rcContent.Left;
            int top      = rcContent.Top;
            int height   = rcContent.Height;
            int position = (int)this.m_Animation.Current;

            Rectangle rcMiddle = new Rectangle(position - this.m_ProgressLengthReal, top, this.m_ProgressLengthReal, height);
            Rectangle rcLeft   = new Rectangle(left, top, rcMiddle.Left - left, height);
            Rectangle rcRight  = new Rectangle(rcMiddle.Right, top, rect.Right - 1 - rcMiddle.Right, height);

            //渲染进度
            using (new ClipGraphics(g, rcContent, CombineMode.Intersect))
            {
                if (RectangleEx.IsVisible(rcLeft))
                {
                    this.Sprite.BorderVisibleStyle = BorderVisibleStyle.None;
                    this.Sprite.BackColor          = this.BackColor;
                    this.Sprite.State = this.State;
                    this.Sprite.BeginRender(g);
                    this.Sprite.RenderBackColor(rcLeft);
                    this.Sprite.EndRender();
                }
                if (RectangleEx.IsVisible(rcMiddle))
                {
                    this.Sprite.BorderVisibleStyle = BorderVisibleStyle.None;
                    this.Sprite.BackColor          = this.ProgressColor;
                    this.Sprite.State = this.State;
                    this.Sprite.BeginRender(g);
                    this.Sprite.RenderBackColor(rcMiddle);
                    this.Sprite.EndRender();
                }
                if (RectangleEx.IsVisible(rcRight))
                {
                    this.Sprite.BorderVisibleStyle = BorderVisibleStyle.None;
                    this.Sprite.BackColor          = this.BackColor;
                    this.Sprite.State = this.State;
                    this.Sprite.BeginRender(g);
                    this.Sprite.RenderBackColor(rcRight);
                    this.Sprite.EndRender();
                }
            }

            //渲染边框
            this.Sprite.BorderVisibleStyle = BorderVisibleStyle.All;
            this.Sprite.BorderColor        = this.BorderColor;
            this.Sprite.BeginRender(g);
            this.Sprite.RenderBorder(rect);
            this.Sprite.EndRender();
        }
Exemplo n.º 12
0
        /// <summary>
        /// 准备渲染字符串路径,返回字符串路径的大小(测量字符串路径大小,画布有限制)
        /// </summary>
        /// <param name="rect">测量时,画布限制.与绘制区域无关</param>
        /// <returns>字符串路径大小</returns>
        public Size BeginRenderString(Rectangle rect)
        {
            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect) || this.Text == null || this.Text.Length <= 0)
            {
                return(Size.Empty);
            }

            Size strSize;

            this.m_CurrentStringPathRect = RenderEngine.BeginDrawString(this.m_Graphics, this.Text, this.Font, rect, out strSize);
            this.m_CurrentStringSize     = strSize;
            return(this.CurrentStringPathRect.Size);
        }
Exemplo n.º 13
0
        public RectangleF GetMouseRectangleOfCandidates(FullGridMap map)
        {
            var(cw, ch) = CandidateSize;
            int min = map.SetAt(0);
            int max = map.SetAt(^ 1);
            var pt1 = GetMousePointInCenter(min / 9, min % 9);
            var pt2 = GetMousePointInCenter(max / 9, max % 9);

            pt1.X -= cw / 2;
            pt1.Y -= ch / 2;
            pt2.X += cw / 2;
            pt2.Y += ch / 2;
            return(RectangleEx.CreateInstance(pt1, pt2));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 正式渲染字符串路径
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void EndRenderString(Rectangle rect)
        {
            this.m_StringRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_StringRect) || this.Text == null || this.Text.Length <= 0)
            {
                return;
            }

            using (Brush brush = new SolidBrush(this.CurrentForeColor))
            {
                RenderEngine.EndDrawString(this.m_Graphics, this.m_Text, this.m_Font, brush, this.CurrentStringRect, this.m_TextAlign, this.CurrentStringPathRect, this.CurrentStringSize);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Loads a new tile from an XML element
        /// </summary>
        /// <param name="tile">XML element to load</param>
        /// <param name="sheets">Spritesheets for caching</param>
        /// <returns></returns>
        public static Tile LoadFromXML(XElement tile, List <Spritesheet> sheets = null)
        {
            //TODO: add support for rounded tiles from XML
            Spritesheet tempSheet = null;

            if (sheets.Count(s => s.SpritesheetID == tile.Element("Spritesheet").Value) > 0)              //if sheets contains element
            {
                tempSheet = sheets.First(s => s.SpritesheetID == tile.Element("Spritesheet").Value);
            }

            //generate new rectangle from position and size
            Rectangle tileRect = RectangleEx.FromArray(
                (tile.Element("Position").Value + "," + tile.Element("Size").Value).Split(','));

            return(new Tile(tileRect, tile.Element("TileID").Value, false, tempSheet));
        }
Exemplo n.º 16
0
        /// <summary>
        /// 渲染控件
        /// </summary>
        /// <param name="e">数据</param>
        protected override void RenderSelf(PaintEventArgs e)
        {
            //准备
            Graphics  g    = e.Graphics;
            Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding);

            //渲染
            this.Sprite.BackgroundImage       = this.m_Animation.Current;
            this.Sprite.BackgroundImageLayout = ImageLayout.Stretch;
            this.Sprite.BorderColor           = this.BorderColor;
            this.Sprite.BorderVisibleStyle    = this.BorderVisibleStyle;
            this.Sprite.State = this.State;
            this.Sprite.BeginRender(g);
            this.Sprite.RenderBackgroundImage(rect);
            this.Sprite.RenderBorder(rect);
            this.Sprite.EndRender();
        }
Exemplo n.º 17
0
        /// <summary>
        /// 渲染控件
        /// </summary>
        /// <param name="e">数据</param>
        protected override void RenderSelf(PaintEventArgs e)
        {
            //准备
            Graphics  g    = e.Graphics;
            Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding);

            //渲染
            this.Sprite.BackColor          = this.BackColor;
            this.Sprite.Font               = this.Font;
            this.Sprite.Text               = this.Text;
            this.Sprite.TextRenderingHint  = this.TextRenderingHint;
            this.Sprite.TextAlign          = this.TextAlign;
            this.Sprite.BorderVisibleStyle = BorderVisibleStyle.None;
            this.Sprite.State              = this.State;
            this.Sprite.BeginRender(g);
            this.Sprite.RenderText(rect);
            this.Sprite.EndRender();
        }
Exemplo n.º 18
0
        /// <summary>
        /// 渲染标签样式分组控件边框色
        /// </summary>
        /// <param name="rect">渲染区域</param>
        /// <param name="tabSize">左上角标签大小</param>
        /// <param name="tabRound">标签右上角是否发圆角</param>
        /// <param name="tabRadius">标签右上角圆角半径</param>
        public void RenderBorderColorGroupBoxTab(Rectangle rect, Size tabSize, bool tabRound, float tabRadius)
        {
            this.m_BorderColorRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BorderColorRect))
            {
                return;
            }

            //重置剪切区
            this.m_Graphics.SetClip(this.m_GraphicsClip, CombineMode.Replace);

            //绘制内边框
            if (this.m_InnerBorderVisibleStyle != BorderVisibleStyle.None)
            {
                using (Brush brush = RenderEngine.CreateBrush(this.CurrentInnerBorderBrushRect, this.CurrentInnerBorderColor, this.m_InnerBorderColorPos1, this.m_InnerBorderColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_InnerBorderBlendStyle))
                {
                    using (Pen pen = RenderEngine.CreatePen(brush, 1, this.m_InnerBorderDashStyle, this.m_InnerBorderDashPattern, this.m_InnerBorderDashCap, this.m_InnerBorderDashOffset))
                    {
                        Size innerBorderTabSize = new Size(tabSize.Width - 3, tabSize.Height);
                        using (GraphicsPath path = RenderEngine.CreateGroupBoxTabGraphicsPath(this.CurrentInnerBorderPathRect, this.m_RoundStyle, this.m_RoundRadius, innerBorderTabSize, tabRound, tabRadius, false))
                        {
                            this.m_Graphics.DrawPath(pen, path);
                        }
                    }
                }
            }

            //绘制边框
            if (this.m_BorderVisibleStyle != BorderVisibleStyle.None)
            {
                using (Brush brush = RenderEngine.CreateBrush(this.CurrentBorderBrushRect, this.CurrentBorderColor, this.m_BorderColorPos1, this.m_BorderColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_BorderBlendStyle))
                {
                    using (Pen pen = RenderEngine.CreatePen(brush, 1, this.m_BorderDashStyle, this.m_BorderDashPattern, this.m_BorderDashCap, this.m_BorderDashOffset))
                    {
                        Size borderTabSize = new Size(tabSize.Width - 1, tabSize.Height);
                        using (GraphicsPath path = RenderEngine.CreateGroupBoxTabGraphicsPath(this.CurrentBorderPathRect, this.m_RoundStyle, this.m_RoundRadius, borderTabSize, tabRound, tabRadius, false))
                        {
                            this.m_Graphics.DrawPath(pen, path);
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// 渲染背景色
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderBackColor(Rectangle rect)
        {
            this.m_BackColorRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackColorRect))
            {
                return;
            }

            using (Brush brush = RenderEngine.CreateBrush(this.CurrentBackColorBrushRect, this.CurrentBackColor, this.m_BackColorPos1, this.m_BackColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_BackColorBlendStyle))
            {
                if (float.IsNaN(this.m_RoundRadius) || this.m_RoundRadius <= 0f)
                {
                    this.m_Graphics.FillRectangle(brush, this.CurrentBackColorPathRect);
                }
                else
                {
                    this.m_Graphics.FillPath(brush, this.CurrentBackColorPath);
                }
            }
        }
Exemplo n.º 20
0
        private void loadTile(Rectangle drawBox, string ID)
        {
            this.drawBox = drawBox;
            string    path    = AppDomain.CurrentDomain.BaseDirectory + @"Content\tiles\" + ID + ".xml";
            XDocument doc     = XDocument.Load(path);
            string    sheetID = doc.Descendants("Spritesheet").First().Value;

            if (sheet == null || sheet.SpritesheetID != sheetID)             //if loaded spritesheet doesn't match
            {
                sheet = new Spritesheet(sheetID);
            }
            //add sourceboxes, middle is the sourcebox if it is not rounded
            middle = RectangleEx.FromArray(doc.Descendants("Middle").Elements("Box").First().Value.Split(','));
            if (rounded)
            {
                topLeft     = RectangleEx.FromArray(doc.Descendants("TopLeft").Elements("Box").First().Value.Split(','));
                topRight    = RectangleEx.FromArray(doc.Descendants("TopRight").Elements("Box").First().Value.Split(','));
                bottomLeft  = RectangleEx.FromArray(doc.Descendants("BottomLeft").Elements("Box").First().Value.Split(','));
                bottomRight = RectangleEx.FromArray(doc.Descendants("BottomRight").Elements("Box").First().Value.Split(','));
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 渲染九宫格背景图
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderBackgroundImage9(Rectangle rect)
        {
            this.m_BackgroundImage9Rect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackgroundImage9Rect) || this.CurrentBackgroundImage9 == null)
            {
                return;
            }

            if (this.m_State == State.Disabled && this.m_BackgroundImage9GrayOnDisabled)//灰色图片
            {
                using (Image img = RenderEngine.GetGrayImage(this.CurrentBackgroundImage9))
                {
                    RenderEngine.DrawBackgroundImage9(this.m_Graphics, img, this.CurrentBackgroundImage9Rect, this.m_BackgroundImage9Padding.Left, this.m_BackgroundImage9Padding.Top, this.m_BackgroundImage9Padding.Right, this.m_BackgroundImage9Padding.Bottom, this.m_BackgroundImage9Layout);
                }
            }
            else//原图
            {
                RenderEngine.DrawBackgroundImage9(this.m_Graphics, this.CurrentBackgroundImage9, this.CurrentBackgroundImage9Rect, this.m_BackgroundImage9Padding.Left, this.m_BackgroundImage9Padding.Top, this.m_BackgroundImage9Padding.Right, this.m_BackgroundImage9Padding.Bottom, this.m_BackgroundImage9Layout);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// 渲染背景图
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderBackgroundImage(Rectangle rect)
        {
            this.m_BackgroundImageRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackgroundImageRect) || this.CurrentBackgroundImage == null)
            {
                return;
            }

            if (this.m_State == State.Disabled && this.m_BackgroundImageGrayOnDisabled)//灰色图片
            {
                using (Image img = RenderEngine.GetGrayImage(this.CurrentBackgroundImage))
                {
                    RenderEngine.DrawBackgroundImage(this.m_Graphics, img, this.CurrentBackgroundImageRect, this.m_BackgroundImageLayout);
                }
            }
            else//原图
            {
                RenderEngine.DrawBackgroundImage(this.m_Graphics, this.CurrentBackgroundImage, this.CurrentBackgroundImageRect, this.m_BackgroundImageLayout);
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Get the rectangle (4 mouse points) for the specified region.
 /// </summary>
 /// <param name="region">The region.</param>
 /// <returns>The rectangle.</returns>
 /// <exception cref="ArgumentOutOfRangeException">
 /// Throws when the region is less than 0 or greater than 26.
 /// </exception>
 public RectangleF GetMousePointRectangleForRegion(int region)
 {
     if (region >= 0 && region < 9)
     {
         return(RectangleEx.CreateInstance(
                    GridPoints[region % 3 * 9, region / 3 * 9],
                    GridPoints[region % 3 * 9 + 9, region / 3 * 9 + 9]));
     }
     else if (region >= 9 && region < 18)
     {
         region -= 9;
         return(RectangleEx.CreateInstance(GridPoints[0, region * 3], GridPoints[27, region * 3 + 3]));
     }
     else if (region >= 18 && region < 27)
     {
         region -= 18;
         return(RectangleEx.CreateInstance(GridPoints[region * 3, 0], GridPoints[region * 3 + 3, 27]));
     }
     else
     {
         throw new ArgumentOutOfRangeException(nameof(region));
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// 渲染边框颜色(RoundStyle圆角样式,BorderStyle确定绘制哪个边,BlendStyle混合方式)
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderBorder(Rectangle rect)
        {
            this.m_BorderColorRect = rect;

            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BorderColorRect))
            {
                return;
            }

            //重置剪切区
            this.m_Graphics.SetClip(this.m_GraphicsClip, CombineMode.Replace);

            //绘制内边框
            if (this.m_InnerBorderVisibleStyle != BorderVisibleStyle.None)
            {
                using (Brush brush = RenderEngine.CreateBrush(this.CurrentInnerBorderBrushRect, this.CurrentInnerBorderColor, this.m_InnerBorderColorPos1, this.m_InnerBorderColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_InnerBorderBlendStyle))
                {
                    using (Pen pen = RenderEngine.CreatePen(brush, 1, this.m_InnerBorderDashStyle, this.m_InnerBorderDashPattern, this.m_InnerBorderDashCap, this.m_InnerBorderDashOffset))
                    {
                        RenderEngine.DrawBorder(this.m_Graphics, pen, this.CurrentInnerBorderPathRect, this.m_InnerBorderVisibleStyle, this.m_RoundCornerStyle, this.m_RoundStyle, this.m_RoundRadius, false);
                    }
                }
            }

            //绘制边框
            if (this.m_BorderVisibleStyle != BorderVisibleStyle.None)
            {
                using (Brush brush = RenderEngine.CreateBrush(this.CurrentBorderBrushRect, this.CurrentBorderColor, this.m_BorderColorPos1, this.m_BorderColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_BorderBlendStyle))
                {
                    using (Pen pen = RenderEngine.CreatePen(brush, 1, this.m_BorderDashStyle, this.m_BorderDashPattern, this.m_BorderDashCap, this.m_BorderDashOffset))
                    {
                        RenderEngine.DrawBorder(this.m_Graphics, pen, this.CurrentBorderPathRect, this.m_BorderVisibleStyle, this.m_RoundCornerStyle, this.m_RoundStyle, this.m_RoundRadius, false);
                    }
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 渲染Metrol按下边框
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderMetroPress(Rectangle rect)
        {
            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
            {
                return;
            }

            //左侧
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Left) != 0)
            {
                rect.X     += 2;
                rect.Width -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Left) != 0)
            {
                rect.X     += 1;
                rect.Width -= 1;
            }

            //上边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Top) != 0)
            {
                rect.Y      += 2;
                rect.Height -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Top) != 0)
            {
                rect.Y      += 1;
                rect.Height -= 1;
            }

            //右边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Right) != 0)
            {
                rect.Width -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Right) != 0)
            {
                rect.Width -= 1;
            }

            //下边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
            {
                rect.Height -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
            {
                rect.Height -= 1;
            }

            //设置剪切区
            this.m_Graphics.SetClip(rect);

            //绘制宽边框
            using (GraphicsPath pathBorder = RenderEngine.CreateGraphicsPath(rect),
                   pathBorderIn = RenderEngine.CreateGraphicsPath(Rectangle.Inflate(rect, -3, -3)))
            {
                //边框区域
                pathBorder.AddPath(pathBorderIn, true);

                //绘制
                using (Brush brush = new SolidBrush(this.CurrentBorderColor))
                {
                    this.m_Graphics.FillPath(brush, pathBorder);
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// 绘制Metrol选中边框
        /// </summary>
        /// <param name="rect">渲染区域</param>
        public void RenderMetroCheck(Rectangle rect)
        {
            if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
            {
                return;
            }

            //左侧
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Left) != 0)
            {
                rect.X     += 2;
                rect.Width -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Left) != 0)
            {
                rect.X     += 1;
                rect.Width -= 1;
            }

            //上边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Top) != 0)
            {
                rect.Y      += 2;
                rect.Height -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Top) != 0)
            {
                rect.Y      += 1;
                rect.Height -= 1;
            }

            //右边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Right) != 0)
            {
                rect.Width -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Right) != 0)
            {
                rect.Width -= 1;
            }

            //下边
            if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
            {
                rect.Height -= 2;
            }
            else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
            {
                rect.Height -= 1;
            }

            //设置剪切区
            this.m_Graphics.SetClip(rect);

            //绘制宽边框
            using (GraphicsPath pathBorder = RenderEngine.CreateGraphicsPath(rect),
                   pathBorderIn = RenderEngine.CreateGraphicsPath(Rectangle.Inflate(rect, -3, -3)),
                   pathTriangle = new GraphicsPath())
            {
                //边框区域
                pathBorder.AddPath(pathBorderIn, true);

                //右上角三角区域
                Point[] points = new Point[] {
                    new Point(rect.X + rect.Width - 40, rect.Y),
                    new Point(rect.X + rect.Width, rect.Y),
                    new Point(rect.X + rect.Width, rect.Y + 40)
                };
                pathTriangle.AddPolygon(points);

                //绘制
                using (Brush brush = new SolidBrush(this.CurrentBackColor))
                {
                    this.m_Graphics.FillPath(brush, pathBorder);
                    this.m_Graphics.FillPath(brush, pathTriangle);
                }
            }

            //绘制对号
            RenderEngine.DrawCheck(this.m_Graphics, new Rectangle(rect.Right - 22, rect.Y + 2, 20, 20), this.CurrentForeColor);
        }
Exemplo n.º 27
0
        /// <summary>
        /// 创建画刷,渲染背景和边框使用
        /// </summary>
        /// <param name="rect">画刷区域</param>
        /// <param name="baseColor">基色</param>
        /// <param name="pos1">基色位置1</param>
        /// <param name="pos2">基色位置2</param>
        /// <param name="reverse">是否反转</param>
        /// <param name="mode">渐变模式</param>
        /// <param name="style">样式</param>
        /// <returns>画刷</returns>
        public static Brush CreateBrush(Rectangle rect, Color baseColor, float pos1, float pos2, bool reverse, LinearGradientMode mode, BlendStyle style)
        {
            Brush brush = null;

            RectangleEx.MakeNotEmpty(ref rect);
            switch (style)
            {
            case BlendStyle.Solid:
            {
                SolidBrush brushTmp = new SolidBrush(baseColor);
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.Gradient:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosGradient(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeIn:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeIn(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeOut(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            case BlendStyle.FadeInFadeOut:
            {
                LinearGradientBrush brushTmp = new LinearGradientBrush(rect, Color.Empty, Color.Empty, mode);
                //画刷设置
                ColorBlend blendTmp = new ColorBlend();
                Color[]    colors;
                float[]    positions;
                RenderEngine.GetColorPosFadeInFadeOut(baseColor, pos1, pos2, reverse, false, out colors, out positions);
                blendTmp.Colors    = colors;
                blendTmp.Positions = positions;
                //
                brushTmp.InterpolationColors = blendTmp;
                brush    = brushTmp;
                brushTmp = null;
            }
            break;

            default:
                break;
            }
            return(brush);
        }
Exemplo n.º 28
0
        //  -----------------------------
        //  |                           |
        //  |     TEXT                  |
        //  |                           |
        //  |         <----bufer------->|
        //  -----------------------------

        /// <summary>
        /// Tạo một hình bao quanh text
        /// </summary>
        /// <param name="text">Text cần bound</param>
        /// <param name="boundType">Kiểu bao </param>
        /// <param name="bufer">Khoảng bufer</param>
        public static void CreateTextBound(DBText text, BoundType boundType, double bufer = 0)
        {
            RectangleEx rec = GetTextBounds(text);

            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database acDb  = acDoc.Database;
            Editor   acEd  = acDoc.Editor;

            switch (boundType)
            {
            case BoundType.Rectangle:
            {
                using (Transaction tr = acDoc.TransactionManager.StartTransaction())
                {
                    Polyline pl = new Polyline();
                    pl.AddVertexAt(0, rec.LowerLeft, 0, 0, 0);
                    pl.AddVertexAt(1, rec.UpperLeft, 0, 0, 0);
                    pl.AddVertexAt(2, rec.UpperRight, 0, 0, 0);
                    pl.AddVertexAt(3, rec.LowerRight, 0, 0, 0);
                    pl.Closed = true;
                    //pl.AddVertexAt(4, rec.LowerLeft, 0, 0, 0);

                    BlockTableRecord bRec = tr.GetObject(acDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    bRec.AppendEntity(pl);
                    tr.AddNewlyCreatedDBObject(pl, true);
                    tr.Commit();
                }
                break;
            }

            case BoundType.Circle:
            {
                using (Transaction tr = acDoc.TransactionManager.StartTransaction())
                {
                    Circle c = new Circle();

                    c.Center = new Point3d(rec.Center.X, rec.Center.Y, 0);
                    double radius = Enesy.EnesyCAD.Helper.Point2dHelper.Distance(rec.LowerLeft, rec.Center);
                    c.Radius = radius;

                    BlockTableRecord bRec = tr.GetObject(acDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    bRec.AppendEntity(c);
                    tr.AddNewlyCreatedDBObject(c, true);
                    tr.Commit();
                }
                break;
            }

            case BoundType.Triangle:
            {
                using (Transaction tr = acDoc.TransactionManager.StartTransaction())
                {
                    Circle c = new Circle();

                    c.Center = new Point3d(rec.Center.X, rec.Center.Y, 0);
                    double radius = Enesy.EnesyCAD.Helper.Point2dHelper.Distance(rec.LowerLeft, rec.Center);
                    c.Radius = radius;
                    double cos30  = Math.Sqrt(3) / 2;
                    double tang30 = 0.5 / cos30;

                    //
                    Point2d p1 = Enesy.EnesyCAD.Helper.Point2dHelper.Offset2d(Enesy.EnesyCAD.Helper.Point3dHelper.ToPoint2d(c.Center), 0, 2 * radius);
                    Point2d p2 = Enesy.EnesyCAD.Helper.Point2dHelper.Offset2d(Enesy.EnesyCAD.Helper.Point3dHelper.ToPoint2d(c.Center), -radius / tang30, -radius);
                    Point2d p3 = Enesy.EnesyCAD.Helper.Point2dHelper.Offset2d(Enesy.EnesyCAD.Helper.Point3dHelper.ToPoint2d(c.Center), radius / tang30, -radius);

                    Polyline pl = new Polyline();
                    pl.AddVertexAt(0, p1, 0, 0, 0);
                    pl.AddVertexAt(1, p2, 0, 0, 0);
                    pl.AddVertexAt(2, p3, 0, 0, 0);
                    pl.Closed = true;

                    BlockTableRecord bRec = tr.GetObject(acDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    bRec.AppendEntity(pl);
                    tr.AddNewlyCreatedDBObject(pl, true);
                    tr.Commit();
                }
                break;
            }

            case BoundType.None:
            {
                break;
            }

            default: break;
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Trả về một Rectangle bao quanh một chuỗi
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static RectangleEx GetTextBounds(DBText s, double bufer = 0.1)
        {
            //bufer *= s.Height;

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            Autodesk.AutoCAD.GraphicsInterface.TextStyle style = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
            byte n;

            Transaction tr = db.TransactionManager.StartTransaction();

            try
            {
                using (tr)
                {
                    BlockTableRecord btr            = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    string           text           = s.TextString;
                    TextStyleTable   textStyleTable = tr.GetObject
                                                      (
                        db.TextStyleTableId,
                        OpenMode.ForRead
                                                      ) as TextStyleTable;

                    string currentTextStyle = Application.GetSystemVariable("TEXTSTYLE").ToString();

                    ObjectId textStyleId = ObjectId.Null;
                    textStyleId = textStyleTable[currentTextStyle];
                    Autodesk.AutoCAD.GraphicsInterface.TextStyle iStyle
                        = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();

                    // get textstyle of newly created text
                    TextStyleTableRecord txtbtr = (TextStyleTableRecord)tr.GetObject(textStyleId, OpenMode.ForRead);
                    // copy properties from TextStyleTableRecord and dbtext to temp AcGi.TextStyle (just very limited one for the future calculation)
                    style.FileName = txtbtr.FileName;
                    // then copy properties from existing text
                    style.TextSize       = s.Height; // txtbtr.TextSize;
                    style.ObliquingAngle = s.Oblique;
                    style.XScale         = s.WidthFactor;
                    // load temp style record
                    try
                    {
                        n = style.LoadStyleRec;
                    }
                    catch { return(null); }// something wrong then exit on error

                    // find out the extents
                    Point2d minpt, maxpt;
                    // get extends of text
                    Extents2d ex = style.ExtentsBox(text, true, true, null);

                    minpt = ex.MinPoint;
                    maxpt = ex.MaxPoint;



                    tr.Commit();
                    RectangleEx rec = new RectangleEx(Math.Abs(minpt.X - maxpt.X),
                                                      Math.Abs(minpt.Y - maxpt.Y));

                    Point2d textPos = new Point2d(s.Position.X, s.Position.Y);
                    bufer = s.Height * 0.3;

                    rec.LowerLeft  = new Point2d(textPos.X - bufer, textPos.Y - bufer);
                    rec.UpperLeft  = new Point2d(rec.LowerLeft.X, rec.LowerLeft.Y + rec.Height + 2 * bufer);
                    rec.UpperRight = new Point2d(rec.UpperLeft.X + rec.Width + 2 * bufer, rec.UpperLeft.Y);
                    rec.LowerRight = new Point2d(rec.UpperRight.X, rec.LowerLeft.Y);

                    return(rec);
                }
            }
            catch (System.Exception exc)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(exc.Message + "\n" + exc.StackTrace);
                return(null);
            }
            finally { }
        }
        /// <summary>
        /// 对指定控件的所有子控件重新计算布局
        /// </summary>
        /// <param name="control">指定控件</param>
        internal static void DoLayoutInternal(IUIControl control)
        {
            if (control.UIControls.Count <= 0)
            {
                return;
            }
            control.BeginUpdate();
            try
            {
                Rectangle rcClient = control.ClientRectangle;
                Rectangle rcDock   = rcClient;
                foreach (UIControl child in control.UIControls)
                {
                    try
                    {
                        //停靠
                        switch (child.Dock)
                        {
                        case DockStyle.Left:
                            child.m_PreferredX      = rcDock.Left;
                            child.m_PreferredY      = rcDock.Top;
                            child.m_PreferredHeight = rcDock.Height;
                            child.SetBoundsCore();
                            if (child.Visible)
                            {
                                rcDock = RectangleEx.Subtract(rcDock, new Padding(child.m_PreferredWidth, 0, 0, 0));
                            }
                            continue;

                        case DockStyle.Top:
                            child.m_PreferredX     = rcDock.Left;
                            child.m_PreferredY     = rcDock.Top;
                            child.m_PreferredWidth = rcDock.Width;
                            child.SetBoundsCore();
                            if (child.Visible)
                            {
                                rcDock = RectangleEx.Subtract(rcDock, new Padding(0, child.m_PreferredHeight, 0, 0));
                            }
                            continue;

                        case DockStyle.Right:
                            child.m_PreferredX      = rcDock.Right - child.m_PreferredWidth;
                            child.m_PreferredY      = rcDock.Top;
                            child.m_PreferredHeight = rcDock.Height;
                            child.SetBoundsCore();
                            if (child.Visible)
                            {
                                rcDock = RectangleEx.Subtract(rcDock, new Padding(0, 0, child.m_PreferredWidth, 0));
                            }
                            continue;

                        case DockStyle.Bottom:
                            child.m_PreferredX     = rcDock.Left;
                            child.m_PreferredY     = rcDock.Bottom - child.m_PreferredHeight;
                            child.m_PreferredWidth = rcDock.Width;
                            child.SetBoundsCore();
                            if (child.Visible)
                            {
                                rcDock = RectangleEx.Subtract(rcDock, new Padding(0, 0, 0, child.m_PreferredHeight));
                            }
                            continue;

                        case DockStyle.Fill:
                            child.m_PreferredX      = rcDock.Left;
                            child.m_PreferredY      = rcDock.Top;
                            child.m_PreferredWidth  = rcDock.Width;
                            child.m_PreferredHeight = rcDock.Height;
                            child.SetBoundsCore();
                            if (child.Visible)
                            {
                                rcDock = control.ClientRectangle;     //下一轮重新布局
                            }
                            continue;
                        }
                        //锚定左右
                        if (child.m_LeftToParent == null || child.m_RightToParent == null)
                        {
                            child.m_LeftToParent  = child.m_PreferredX;
                            child.m_RightToParent = rcClient.Width - child.m_PreferredX - child.m_PreferredWidth;
                        }
                        else
                        {
                            switch (child.Anchor & (AnchorStyles.Left | AnchorStyles.Right))
                            {
                            case AnchorStyles.Left:
                                child.m_PreferredX = child.m_LeftToParent.Value;
                                break;

                            case AnchorStyles.Right:
                                child.m_PreferredX = rcClient.Width - child.m_RightToParent.Value - child.m_PreferredWidth;
                                break;

                            case AnchorStyles.Left | AnchorStyles.Right:
                                child.m_PreferredX     = child.m_LeftToParent.Value;
                                child.m_PreferredWidth = rcClient.Width - child.m_LeftToParent.Value - child.m_RightToParent.Value;
                                break;

                            default:
                                child.m_PreferredX = child.m_LeftToParent.Value + (rcClient.Width - child.m_LeftToParent.Value - child.m_PreferredWidth - child.m_RightToParent.Value) / 2;
                                break;
                            }
                        }
                        //锚定上下
                        if (child.m_TopToParent == null || child.m_BottomToParent == null)
                        {
                            child.m_TopToParent    = child.m_PreferredY;
                            child.m_BottomToParent = rcClient.Height - child.m_PreferredY - child.m_PreferredHeight;
                        }
                        else
                        {
                            switch (child.Anchor & (AnchorStyles.Top | AnchorStyles.Bottom))
                            {
                            case AnchorStyles.Top:
                                child.m_PreferredY = child.m_TopToParent.Value;
                                break;

                            case AnchorStyles.Bottom:
                                child.m_PreferredY = rcClient.Height - child.m_BottomToParent.Value - child.m_PreferredHeight;
                                break;

                            case AnchorStyles.Top | AnchorStyles.Bottom:
                                child.m_PreferredY      = child.m_TopToParent.Value;
                                child.m_PreferredHeight = rcClient.Height - child.m_TopToParent.Value - child.m_BottomToParent.Value;
                                break;

                            default:
                                child.m_PreferredY = child.m_TopToParent.Value + (rcClient.Height - child.m_TopToParent.Value - child.m_PreferredHeight - child.m_BottomToParent.Value) / 2;
                                break;
                            }
                        }
                        child.SetBoundsCore();
                    }
                    finally
                    {
                        DoLayoutInternal(child);
                    }
                }
            }
            finally
            {
                control.EndUpdate();
            }
        }