예제 #1
0
        /// <summary>
        /// 绘制控件的背景。
        /// </summary>
        /// <param name="e"></param>
        public virtual void DrawBackground(BackgroundRenderEventArgs e)
        {
            var control = e.Control as Control;

            if (control == null)
            {
                return;
            }

            e.Graphics.Clear(control.BackColor);

            if (control.BackgroundImage != null)
            {
                var imgRect    = new Rectangle(0, 0, control.BackgroundImage.Width, control.BackgroundImage.Height);
                var offsetRect = e.Bounds;
                offsetRect.Offset(0, -e.Bounds.Y);

                switch (control.BackgroundImageLayout)
                {
                case ImageLayout.None:
                    imgRect.Offset(0, e.Bounds.Y);
                    imgRect = GetImageRectByAlignment(e.Bounds, imgRect, e.Control.BackgroundImageAligment);
                    e.Graphics.DrawImage(control.BackgroundImage, imgRect);
                    break;

                case ImageLayout.Tile:
                    for (var i = e.Bounds.X; i < e.Bounds.Width; i += imgRect.Width)
                    {
                        for (var j = e.Bounds.Y; j < e.Bounds.Height; j += imgRect.Height)
                        {
                            e.Graphics.DrawImage(control.BackgroundImage, new Rectangle(i, j, imgRect.Width, imgRect.Height));
                        }
                    }

                    break;

                case ImageLayout.Stretch:
                    e.Graphics.DrawImage(control.BackgroundImage, e.Bounds);
                    break;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 绘制 <see cref="TreeListItem"/> 的背景。
        /// </summary>
        /// <param name="e"></param>
        protected virtual void DrawItemBackground(TreeListItemRenderEventArgs e)
        {
            //绘制背景图像
            if (e.Item.TreeList.BackgroundImage != null)
            {
                e.Graphics.KeepClip(e.Bounds, () =>
                {
                    var be = new BackgroundRenderEventArgs(e.Item.TreeList, e.Graphics, e.Item.TreeList.GetBoundSet().ItemBound);
                    ThemeManager.BaseRenderer.DrawBackground(be);
                });
            }

            var backColor = GetItemBackgroundColor(e);

            if (!backColor.IsEmpty)
            {
                using (var brush = new SolidBrush(backColor))
                {
                    e.Graphics.FillRectangle(brush, e.Bounds);
                }
            }
        }