示例#1
0
        public override void Draw(Graphics graphics)
        {
            #region 背景色
            if (!BackColor.IsEmpty)
            {
                using (var brush = new SolidBrush(this.BackColor))
                {
                    graphics.FillRectangle(brush, this.Rectangle);
                }
            }
            #endregion

            if (TableHeadDrawing != null)
            {
                var args = new TableHeadDrawEventArgs()
                {
                    Cancel = false, Graphics = graphics, TableHead = this
                };
                TableHeadDrawing(args);
                if (args.Cancel)
                {
                    return;
                }
            }

            if (!string.IsNullOrEmpty(Text))
            {
                var font      = this.Font == null ? SystemFonts.DefaultFont : this.Font;
                var foreColor = this.ForeColor.IsEmpty ? SystemColors.WindowText : this.ForeColor;
                var fontSize  = graphics.MeasureString(this.Text, font);

                GDIHelper.DrawString(graphics, this.Rectangle, font, this.Text, foreColor, Align);
            }
        }
示例#2
0
 public override void Draw(Graphics graphics)
 {
     if (this.isHover)
     {
         GDIHelper.DrawString(graphics, this.Rectangle, Font, Text, ForeColor, this.HoverColor, this.Align, this.RadiusMode, this.Radius);
     }
     else
     {
         GDIHelper.DrawString(graphics, this.Rectangle, Font, Text, ForeColor, this.BackColor, this.Align, this.RadiusMode, this.Radius);
     }
 }
示例#3
0
        /// <summary>
        /// 在指定区域绘制图片(可设置图片透明度) (平铺绘制)
        /// Draws the image.
        /// </summary>
        /// <param name="g">The g.</param>
        /// <param name="rect">The rect.</param>
        /// <param name="img">The img.</param>
        /// User:Ryan  CreateTime:2012-8-3 21:12.
        public static void DrawImage(Graphics g, Rectangle rect, Image img, float opacity)
        {
            if (opacity <= 0)
            {
                return;
            }

            using (ImageAttributes imgAttributes = new ImageAttributes())
            {
                GDIHelper.SetImageOpacity(imgAttributes, opacity >= 1 ? 1 : opacity);
                Rectangle imageRect = new Rectangle(rect.X, rect.Y + rect.Height / 2 - img.Size.Height / 2, img.Size.Width, img.Size.Height);
                g.DrawImage(img, rect, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttributes);
            }
        }
示例#4
0
        public override void Draw(Graphics graphics)
        {
            if (CellDrawing != null)
            {
                var args = new TableCellDrawEventArgs()
                {
                    Cancel = false, Cell = this, Graphics = graphics
                };
                CellDrawing(args);
                if (args.Cancel)
                {
                    return;
                }
            }

            if (!string.IsNullOrEmpty(Text))
            {
                GDIHelper.DrawString(graphics, this.Rectangle, this.Font, Text, ForeColor, Align);
            }
        }
示例#5
0
        private void PaintImage(PaintEventArgs e)
        {
            if (leftRectangle.IsEmpty)
            {
                rightRectangle = new Rectangle(this.Width - 80, (this.Height - 40) / 2, 40, 40);
                leftRectangle  = new Rectangle(40, (this.Height - 40) / 2, 40, 40);
            }

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            using (var brush = new SolidBrush(Color.FromArgb(70, 136, 71)))
            {
                e.Graphics.FillEllipse(brush, rightRectangle);
                e.Graphics.FillEllipse(brush, leftRectangle);
            }

            var font = new Font("宋体", 14, FontStyle.Bold);

            GDIHelper.DrawString(e.Graphics, rightRectangle, font, ">", Color.White, TextAlignment.MiddleCenter);
            GDIHelper.DrawString(e.Graphics, leftRectangle, font, "<", Color.White, TextAlignment.MiddleCenter);
        }
示例#6
0
        /// <summary>
        /// 创建临时背景图片
        /// </summary>
        private Bitmap CreateBacgroundImage()
        {
            Rectangle rect = new Rectangle(this.Padding.Left,
                                           this.Caption.Height,
                                           this.Width - this.Padding.Left - this.Padding.Right,
                                           this.Height - this.Caption.Height - this.Padding.Bottom);
            int   w  = rect.Width;
            int   h  = rect.Height;
            Point p1 = new Point(this.Location.X + this.Padding.Left,
                                 this.Location.Y + this.Caption.Height);
            Point  p       = this.Parent == null ? p1 : this.PointToScreen(p1);
            Bitmap TempImg = new Bitmap(w, h);

            try
            {
                Bitmap img = new Bitmap(w, h);
                using (Graphics g = Graphics.FromImage(TempImg))
                {
                    g.CopyFromScreen(p, new Point(0, 0), new Size(w, h));
                }

                using (Graphics g = Graphics.FromImage(img))
                {
                    GDIHelper.DrawImage(g, new Rectangle(0, 0, w, h), TempImg, 0.36F);
                }

                return(img);
            }
            catch
            {
                return(null);
            }
            finally
            {
                TempImg.Dispose();
            }
        }
示例#7
0
        private void DrawBackground(PaintEventArgs e, Graphics g)
        {
            using (var brush = new SolidBrush(this.BackColor))
            {
                g.FillRectangle(brush, this.ClientRectangle);
            }

            #region 表格边框
            if (BorderStyle != MHtmlBorderType.None && this.BorderSize > 0)
            {
                using (var pen = new Pen(this.BorderColor, this.BorderSize))
                {
                    pen.DashStyle = GetDashStyle(BorderStyle);

                    g.DrawRectangle(pen, new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - BorderSize, this.ClientRectangle.Height - BorderSize));
                }
            }
            #endregion

            var borderSize = this.BorderStyle == MHtmlBorderType.None ? 0 : this.BorderSize;
            var y          = borderSize;
            if (this.TableHead.Visible)
            {
                this.TableHead.Draw(g);
                y += this.TableHead.Height;
            }

            if (this.columnHeadVisible)
            {
                // 表头背景
                using (var brush = new SolidBrush(this.ColumnHeadBackColor))
                {
                    g.FillRectangle(brush, new Rectangle(borderSize, y, this.Width - borderSize * 2, this.ColumnHeadHeight));
                }

                #region 绘制表头

                if (columns != null)
                {
                    var columnWidth = this.equallyColumn ? (this.Width - borderSize * 2) / this.columns.Count : 0;

                    var x     = borderSize;
                    var index = 0;
                    foreach (var item in columns)
                    {
                        item.Width = columnWidth == 0 ? item.Width : columnWidth;
                        var rect = new Rectangle(x, y, item.Width, this.ColumnHeadHeight);
                        if (item.BackColor != Color.Empty)
                        {
                            using (var brush = new SolidBrush(item.BackColor))
                            {
                                g.FillRectangle(brush, rect);
                            }
                        }

                        if (index < columns.Count - 1 && this.VerticalBorderStyle != MHtmlBorderType.None)
                        {
                            using (var pen = new Pen(this.VerticalBorderColor, this.VerticalBorderSize))
                            {
                                pen.DashStyle = GetDashStyle(BorderStyle);

                                g.DrawLine(pen, rect.X + rect.Width - this.VerticalBorderSize, rect.Y, rect.X + rect.Width - this.VerticalBorderSize, rect.Y + rect.Height - borderSize - this.VerticalBorderSize);
                                //g.DrawRectangle(pen, new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - BorderSize, this.ClientRectangle.Height - BorderSize));
                            }
                        }

                        if (!string.IsNullOrEmpty(item.Text))
                        {
                            var font = item.Font == null ? this.Font : item.Font;

                            GDIHelper.DrawString(g, rect, font, item.Text, item.ForeColor.IsEmpty ? this.ForeColor : item.ForeColor, item.Align);
                        }

                        x += item.Width;
                        index++;
                    }
                }
                #endregion
            }
        }
示例#8
0
文件: MLabel.cs 项目: ywscr/MomoForm
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            if (string.IsNullOrEmpty(this.Text))
            {
                this.text = string.Empty;
            }
            var size = e.Graphics.MeasureString(Text, this.Font);
            var row  = (int)size.Width / (this.Width - 6);

            if (Text.Contains(System.Environment.NewLine))
            {
                row += this.Text.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.None).Length;
            }
            else if (Text.Contains("\n"))
            {
                row += this.Text.Split(new string[] { "\n" }, System.StringSplitOptions.None).Length;
            }

            var height = size.Width > this.Width ? (row + 1) * this.Font.Height : 30;

            //using (var brush = new SolidBrush(Color.Black))
            //{
            //    e.Graphics.DrawString(Text, this.Font, brush, new Rectangle(3, this.Caption.Height + 3, this.Width - 6, height));
            //}


            if (this.AutoSize)
            {
                var left   = this.border.Width > 0 ? this.border.Width : this.border.Left;
                var right  = this.border.Width > 0 ? this.border.Width : this.border.Right;
                var bottom = this.border.Width > 0 ? this.border.Width : this.border.Bottom;
                var top    = this.border.Width > 0 ? this.border.Width : this.border.Top;
                var w      = left + right + size.Width;
                var h      = top + bottom + height;

                if (this.Size.Height != (int)h || this.Size.Width != (int)w)
                {
                    this.Size = new Size((int)Math.Ceiling(w), h);
                }
            }

            // 注意,如果使用e.ClipRectangle,容器控件移动过程中,会出现重叠绘制
            if (this.radiusMode != RadiusMode.None && this.radius > 0)
            {
                GDIHelper.DrawString(e.Graphics, ClientRectangle, this.Font, this.Text, this.ForeColor, this.BackgroundColor, Align, RadiusMode, Radius);
            }
            else if (this.border != null && !this.border.IsEmpty)
            {
                var left   = this.border.Width > 0 ? this.border.Width : this.border.Left;
                var right  = this.border.Width > 0 ? this.border.Width : this.border.Right;
                var bottom = this.border.Width > 0 ? this.border.Width : this.border.Bottom;
                var top    = this.border.Width > 0 ? this.border.Width : this.border.Top;
                #region 绘制边框
                using (var pen = new Pen(this.border.Color))
                {
                    if (top > 0)
                    {
                        pen.Width = top;
                        e.Graphics.DrawLine(pen, 0, 0, this.Width, 0);
                    }

                    if (left > 0)
                    {
                        pen.Width = left;
                        e.Graphics.DrawLine(pen, 0, 0, 0, this.Height);
                    }

                    if (right > 0)
                    {
                        pen.Width = right;
                        e.Graphics.DrawLine(pen, this.Width - right, 0, this.Width - right, this.Height);
                    }

                    if (bottom > 0)
                    {
                        pen.Width = bottom;
                        e.Graphics.DrawLine(pen, 0, this.Height - bottom, 0, this.Height - bottom);
                    }
                }
                #endregion

                GDIHelper.DrawString(e.Graphics, new Rectangle(ClientRectangle.X + left, ClientRectangle.Y + top, ClientRectangle.Width - left - right, ClientRectangle.Height - top - bottom), this.Font, this.Text, this.ForeColor, this.Align);
            }
            else
            {
                //using (var brush = new SolidBrush(this.ForeColor))
                //{
                //    e.Graphics.DrawString(Text, Font, brush, new Rectangle(0, 0, this.Width, height));
                //}
                if (row > 1)
                {
                    GDIHelper.DrawString(e.Graphics, new Rectangle(0, 0, this.Width, height), this.Font, this.Text, this.ForeColor, this.Align);
                }
                else
                {
                    GDIHelper.DrawString(e.Graphics, ClientRectangle, this.Font, this.Text, this.ForeColor, this.Align);
                }
            }
        }
示例#9
0
        internal void DrawElement(MHtmlElement element, Graphics graphics)
        {
            var rect = new Rectangle(element.RelativePosition, element.Rectangle.Size);

            if (rect.IsEmpty)
            {
                return;
            }

            #region 边框和背景
            // 圆角模式,忽略边框样式
            if (element.RadiusMode != RadiusMode.None && element.Radius > 0)
            {
                var color1 = element.BackColor.IsEmpty ? Color.Transparent : element.BackColor;
                var color2 = element.BackColorGradient;
                RadiusDrawable.DrawRadius(graphics, rect, element.RadiusMode, element.Radius, element.BackColor, element.BackColorGradient, element.Gradient, element.Border.Color, element.Border.Width);
            }
            // 有边框
            else if (element.Border != null && !element.Border.IsEmpty)
            {
                if (!element.BackColor.IsEmpty)
                {
                    using (var brush = new SolidBrush(element.BackColor))
                    {
                        graphics.FillRectangle(brush, element.Rectangle);
                    }
                }

                var bl = element.Border.Left == 0 ? element.Border.Width : element.Border.Left;
                var bt = element.Border.Top == 0 ? element.Border.Width : element.Border.Top;
                var br = element.Border.Right == 0 ? element.Border.Width : element.Border.Right;
                var bb = element.Border.Bottom == 0 ? element.Border.Width : element.Border.Bottom;

                using (var pen = new Pen(element.Border.Color))
                {
                    pen.DashStyle = element.Border.GetDashStyle();
                    if (bl > 0)
                    {
                        pen.Width = bl;
                        graphics.DrawLine(pen, rect.X, rect.Y, rect.X, rect.Y + rect.Height);
                    }

                    if (bt > 0)
                    {
                        pen.Width = bt;
                        graphics.DrawLine(pen, rect.X, rect.Y, rect.X + rect.Width, rect.Y);
                    }

                    if (br > 0)
                    {
                        pen.Width = br;
                        graphics.DrawLine(pen, rect.X + rect.Width, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
                    }

                    if (bb > 0)
                    {
                        pen.Width = bb;
                        graphics.DrawLine(pen, rect.X, rect.Y + rect.Height, rect.X + rect.Width, rect.Y + rect.Height);
                    }
                }
            }
            else
            {
                // 没有边框,直接处理背景
                if (!element.BackColor.IsEmpty)
                {
                    using (var brush = new SolidBrush(element.BackColor))
                    {
                        graphics.FillRectangle(brush, rect);
                    }
                }
            }
            #endregion

            if (!string.IsNullOrEmpty(element.Text))
            {
                var textRect = new Rectangle(rect.X + element.Padding.Left, rect.Y + element.Padding.Top, rect.Width - element.Padding.Left - element.Padding.Right, rect.Height - element.Padding.Top - element.Padding.Bottom);
                GDIHelper.DrawString(graphics, textRect, element.Font, element.Text, element.ForeColor, element.Align);
            }

            if (element.HasHover)
            {
                Hovers.Add(element);
            }

            if (element.HasClick)
            {
                Clicks.Add(element);
            }

            if (element.HasLeave)
            {
                Leaves.Add(element);
            }

            if (element.Items != null)
            {
                foreach (var item in element.Items)
                {
                    this.DrawElement(item, graphics);
                }
            }
        }