示例#1
0
        private void AddBreadCrumbsChildren(Stack <RadSplitButtonElement> stack, Image firstNodeImage)
        {
            Size     empty    = Size.Empty;
            Graphics graphics = this.CreateGraphics();
            bool     flag     = false;

            while (stack.Count > 0)
            {
                RadSplitButtonElement splitButtonElement = stack.Pop();
                if (!flag)
                {
                    Size size = Size.Ceiling(graphics.MeasureString(splitButtonElement.Text, splitButtonElement.Font));
                    if (!size.IsEmpty && firstNodeImage != null)
                    {
                        splitButtonElement.Image = (Image) new Bitmap(firstNodeImage, new Size(Math.Min(size.Height, firstNodeImage.Width), Math.Min(size.Height, firstNodeImage.Width)));
                    }
                    flag = true;
                }
                splitButtonElement.DropDownOpened += new EventHandler(this.currentSplitButton_DropDownOpened);
                splitButtonElement.DropDownClosed += new EventHandler(this.currentSplitButton_DropDownClosed);
                splitButtonElement.MouseEnter     += new EventHandler(this.currentSplitButton_MouseEnter);
                this.breadCrumbElement.Items.Add((RadItem)splitButtonElement);
            }
            graphics.Dispose();
        }
示例#2
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            htmlLabel.Text = description;

            SizeF sizeF = pe.Graphics.MeasureString(description, new Font("Microsoft Sans Serif", 10, FontStyle.Regular, GraphicsUnit.Pixel));


            //HtmlRenderer.Render(pe.Graphics, description, (RectangleF)pe.ClipRectangle, false);
            sizeF.Width -= 50;
            this.Size    = Size.Ceiling(sizeF);
            //Console.WriteLine(sizeF.Width);



            if (description != null && description.Length > 0)
            {
                if (fixedWidth)
                {
                    TipPainterTools.DrawFixedWidthHelpTipFromCombinedDescription(this, pe.Graphics, Font, null, description);
                }
                else
                {
                    TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, null, description);
                }
            }
        }
示例#3
0
        /// <include file='doc\StatusBarPanel.uex' path='docs/doc[@for="StatusBarPanel.GetContentsWidth"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///     Gets the width of the contents of the panel
        /// </devdoc>
        internal int GetContentsWidth(bool newPanel)
        {
            string text;

            if (newPanel)
            {
                if (this.text == null)
                {
                    text = "";
                }
                else
                {
                    text = this.text;
                }
            }
            else
            {
                text = Text;
            }

            Graphics g  = this.parent.CreateGraphicsInternal();
            Size     sz = Size.Ceiling(g.MeasureString(text, parent.Font));

            if (this.icon != null)
            {
                sz.Width += this.icon.Size.Width + 5;
            }
            g.Dispose();

            int width = sz.Width + SystemInformation.BorderSize.Width * 2 + PANELTEXTINSET * 2 + PANELGAP;

            return(Math.Max(width, minWidth));
        }
示例#4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (object.ReferenceEquals(originalPadding, null))
            {
                originalPadding = this.Padding;
            }
            Graphics  graphics      = e.Graphics;
            Rectangle textRectangle = this.ClientRectangle;
            int       textOffset    = 8;
            Size      textSize;

            textRectangle.X     += textOffset;
            textRectangle.Width -= 2 * textOffset;
            using (StringFormat format = new StringFormat())
            {
                format.HotkeyPrefix = ShowKeyboardCues?System.Drawing.Text.HotkeyPrefix.Show:System.Drawing.Text.HotkeyPrefix.Hide;
                if (RightToLeft == RightToLeft.Yes)
                {
                    format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                }
                textSize = Size.Ceiling(graphics.MeasureString(Text, Font, textRectangle.Width, format));
            }
            this.Padding = new Padding(originalPadding.Left > 2?originalPadding.Left:2, originalPadding.Top + textSize.Height - Font.Height, originalPadding.Right > 2?originalPadding.Right:2, originalPadding.Bottom > 2?originalPadding.Bottom:2);
            base.OnPaint(e);
        }
示例#5
0
        public override int GetOptimalHeight(int width)
        {
            UpdateUIWithFont();
            // compute optimal label height as one line only.
            int height = m_labelTitle.Size.Height;

            // do this to avoid getting parented to the Parking window.
            //
            if (ownerGrid.IsHandleCreated && !IsHandleCreated)
            {
                CreateControl();
            }

            // compute optimal text height
            var      isScalingRequirementMet = DpiHelper.IsScalingRequirementMet;
            Graphics g     = m_labelDesc.CreateGraphicsInternal();
            SizeF    sizef = PropertyGrid.MeasureTextHelper.MeasureText(ownerGrid, g, m_labelTitle.Text, Font, width);
            Size     sz    = Size.Ceiling(sizef);

            g.Dispose();
            var padding = isScalingRequirementMet ? LogicalToDeviceUnits(2) : 2;

            height += (sz.Height * 2) + padding;
            return(Math.Max(height + 2 * padding, isScalingRequirementMet ? LogicalToDeviceUnits(CYDEF) : CYDEF));
        }
示例#6
0
        private void DetermineMaxItemSize(Graphics g, Item[] items, out Size maxItemSizeResult, out Size maxImageSizeResult)
        {
            // Find max image height and width
            int maxImageWidth  = 0;
            int maxImageHeight = 0;
            int maxTextWidth   = 0;
            int maxTextHeight  = 0;

            foreach (Item item in items)
            {
                maxImageWidth  = Math.Max(maxImageWidth, item.Image.Width);
                maxImageHeight = Math.Max(maxImageHeight, item.Image.Height);

                SizeF textSizeF = g.MeasureString(item.Name, Font, new PointF(0, 0), this.stringFormat);
                Size  textSize  = Size.Ceiling(textSizeF);

                maxTextWidth  = Math.Max(textSize.Width, maxTextWidth);
                maxTextHeight = Math.Max(textSize.Height, maxTextHeight);
            }

            int maxItemWidth = this.imageXInset + maxImageWidth + this.imageXInset + this.textLeftMargin + maxTextWidth + this.textRightMargin;

            int maxItemHeight = Math.Max(
                this.imageYInset + maxImageHeight + this.imageYInset,
                this.textVMargin + maxTextHeight + this.textVMargin);

            maxItemSizeResult  = new Size(maxItemWidth, maxItemHeight);
            maxImageSizeResult = new Size(maxImageWidth, maxImageHeight);
        }
示例#7
0
        public static Size GetTipSize(Control control, Graphics graphics, TipSection tipData)
        {
            Size  tipSize  = Size.Empty;
            SizeF tipSizeF = SizeF.Empty;

            RectangleF workingArea = GetWorkingArea(control);

            PointF screenLocation = control.PointToScreen(Point.Empty);

            SizeF maxLayoutSize = new SizeF(workingArea.Right - screenLocation.X - HorizontalBorder * 2,
                                            workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);

            if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0)
            {
                graphics.TextRenderingHint =
                    TextRenderingHint.AntiAliasGridFit;

                tipData.SetMaximumSize(maxLayoutSize);
                tipSizeF = tipData.GetRequiredSize();
                tipData.SetAllocatedSize(tipSizeF);

                tipSizeF += new SizeF(HorizontalBorder * 2,
                                      VerticalBorder * 2);
                tipSize = Size.Ceiling(tipSizeF);
            }

            if (control.ClientSize != tipSize)
            {
                control.ClientSize = tipSize;
            }

            return(tipSize);
        }
示例#8
0
        /// <summary>
        /// Measure the current content of the VisualElement.
        /// </summary>
        /// <param name="measure"></param>
        /// <param name="maxSize">If empty is not used.</param>
        /// <returns></returns>
        protected override SizeF OnMeasureContent(MeasureHelper measure, System.Drawing.SizeF maxSize)
        {
            Size proposedSize;

            if (maxSize != System.Drawing.SizeF.Empty)
            {
                proposedSize = Size.Ceiling(maxSize);

                //Remove the 0 because cause some auto size problems expecially when used with the EndEllipses flag.
                if (proposedSize.Width == 0)
                {
                    proposedSize.Width = int.MaxValue;
                }
                if (proposedSize.Height == 0)
                {
                    proposedSize.Height = int.MaxValue;
                }
            }
            else
            {
                // Declare a proposed size with dimensions set to the maximum integer value.
                proposedSize = new Size(int.MaxValue, int.MaxValue);
            }

            return(System.Windows.Forms.TextRenderer.MeasureText(measure.Graphics, Value, Font, proposedSize, TextFormatFlags));
        }
示例#9
0
        void DrawButtonImageAndText(PaintEventArgs e, TabBarButton button, UIControlStatus ucs)
        {
            if (button.Icon != null && string.IsNullOrEmpty(button.Text))
            {
                PaintHelper.DrawImageInRange(e.Graphics, button.Icon, button.Bounds);
            }
            else if (button.Icon == null && string.IsNullOrEmpty(button.Text))
            {
                DrawButtonText(e, button, ucs);
            }
            else
            {
                Size size = Size.Ceiling(e.Graphics.MeasureString(button.Text, Bar.Font));
                size.Width += button.Icon.Width;
                Rectangle rect = new Rectangle(
                    button.Bounds.X + (button.Bounds.Width - size.Width) / 2,
                    button.Bounds.Y + (button.Bounds.Height - size.Height) / 2,
                    size.Width,
                    size.Height);

                e.Graphics.DrawImage(button.Icon,
                                     new Rectangle(rect.Left, rect.Top + (rect.Height - button.Icon.Height) / 2, button.Icon.Width, button.Icon.Height),
                                     0, 0, button.Icon.Width, button.Icon.Height, GraphicsUnit.Pixel);

                rect.X     += button.Icon.Width;
                rect.Width -= button.Icon.Width;

                e.Graphics.DrawString(button.Text, Bar.Font, new SolidBrush(Bar.ForeColor), rect, PaintHelper.SFCenter);
            }
        }
        protected override Rectangle GetBodyTextRect(System.Drawing.Graphics dc, string text, Rectangle rect)
        {
            SizeF size = dc.MeasureString(text, font, rect.Size.Width,
                                          new StringFormat());

            return(new Rectangle(new Point(0, 0), Size.Ceiling(size)));
        }
示例#11
0
        public override void Paint(Graphics gfx, MapRenderContext context)
        {
            if (!marqueeBounds.IsEmpty)
            {
                gfx.DrawRectangle(Pens.White, marqueeBounds);
                gfx.DrawRectangle(pen, marqueeBounds);
            }

            if (fragment != null)
            {
                foreach (var entry in fragment)
                {
                    var itemRect = context.ToViewport(entry.TileRect).Shrink(2, 2, 1, 1);
                    var brush    = entry.IsConflicted ? Brushes.Red : Brushes.LawnGreen;
                    gfx.FillRectangle(brush, itemRect);
                }
            }

            if (!string.IsNullOrEmpty(hint))
            {
                Size      hintSize = Size.Ceiling(gfx.MeasureString(hint, font));
                Rectangle hintRect = new Rectangle(
                    marqueeBounds.Right - hintSize.Width,
                    marqueeBounds.Bottom - hintSize.Height,
                    hintSize.Width,
                    hintSize.Height);
                gfx.FillRectangle(Brushes.Black, hintRect);
                gfx.DrawString(hint, font, Brushes.White, hintRect);
            }
        }
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics  g = e.Graphics;
            Rectangle rect, rect2;
            int       pbWidth = e.MarginBounds.Width;
            int       pbHeight = e.MarginBounds.Height;
            int       pcWidth = e.MarginBounds.Width;
            int       pcHeight = e.MarginBounds.Height;
            int       ImageWidth1 = b.Width; int ImageHeight1 = b.Height;
            int       ImageWidth2 = c.Width; int ImageHeight2 = c.Height;

            SizeF sizef  = new SizeF(ImageWidth1 / b.HorizontalResolution, ImageHeight1 / b.VerticalResolution);
            float fSeale = Math.Min(pbWidth / sizef.Width, pbHeight / sizef.Height);

            sizef.Width  *= fSeale;
            sizef.Height *= fSeale;
            Size size = Size.Ceiling(sizef);

            rect = new Rectangle(e.MarginBounds.Location.X, e.MarginBounds.Location.Y, size.Width, size.Height);
            g.DrawImage(b, rect);

            SizeF sizef2  = new SizeF(ImageWidth2 / c.HorizontalResolution, ImageHeight2 / c.VerticalResolution);
            float fSeale2 = Math.Min(pcWidth / sizef2.Width, pcHeight / sizef2.Height);

            sizef2.Width  *= fSeale2;
            sizef2.Height *= fSeale2;
            Size size2 = Size.Ceiling(sizef2);

            rect2 = new Rectangle(e.MarginBounds.Location.X, e.MarginBounds.Location.Y + 550, size2.Width, size2.Height);
            g.DrawImage(c, rect2);
        }
        private uint[,] NumberToPixels(int n)
        {
            var s = n.ToString("D");

            using (var bitmap = new Bitmap(2 * SizeNumber * s.Length, 2 * SizeNumber, PixelFormat.Format32bppArgb))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    using (var font = new Font(
                               FontFamily.GenericSansSerif, SizeNumber, FontStyle.Bold, GraphicsUnit.Pixel))
                    {
                        graphics.SmoothingMode     = SmoothingMode.None;
                        graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;

                        var size = Size.Ceiling(graphics.MeasureString(s, font));
                        graphics.DrawString(s, font, new SolidBrush(ColorNumber.ToColor()), 0, 0);

                        var pixels = new uint[size.Height, size.Width];
                        for (var y = 0; y < size.Height; y++)
                        {
                            for (var x = 0; x < size.Width; x++)
                            {
                                pixels[y, x] = (uint)bitmap.GetPixel(x, y).ToArgb();
                            }
                        }
                        return(pixels);
                    }
                }
            }
        }
示例#14
0
文件: IconHandler.cs 项目: zzlvff/Eto
        public void Create(IEnumerable <IconFrame> frames)
        {
            this._frames = frames.ToList();
            var curScale = Screen.PrimaryScreen.LogicalPixelSize;
            var item     = this._frames.FirstOrDefault(r => Math.Abs(r.Scale - curScale) < 0.0001) ?? this._frames.First();

            var size = Size.Ceiling((SizeF)item.PixelSize / (float)item.Scale).ToNS();

            Control      = new NSImage();
            Control.Size = size;
            foreach (var frame in this._frames)
            {
                var rep = frame.Bitmap.ToNS().Representations().First();
                rep.Size = (new SizeF(rep.PixelsWide, rep.PixelsHigh) / (float)frame.Scale).ToNS();
                var mns = rep as IconFrameHandler.LazyImageRep;
                if (mns != null)
                {
                    mns.Size = size;                    //(size.ToEto() * (float)r.Scale).ToNS();
                    var pixelSize = Size.Ceiling(size.ToEto() * (float)frame.Scale);
                    mns.PixelsHigh = pixelSize.Height;
                    mns.PixelsWide = pixelSize.Width;
                }
                Control.AddRepresentation(rep);
            }
        }
示例#15
0
        /// <summary>Set ScrollBar increments and bounds from map dimensions.</summary>
        public virtual void SetScrollLimits(IMapDisplayWinForms model)
        {
            if (model == null)
            {
                return;
            }
            var smallChange = Size.Ceiling(model.GridSize.Scale(MapScale));

            HorizontalScroll.SmallChange = smallChange.Width;
            VerticalScroll.SmallChange   = smallChange.Height;

            var largeChange = Size.Round(ClientSize.Scale(0.75F));

            HorizontalScroll.LargeChange = Math.Max(largeChange.Width, smallChange.Width);
            VerticalScroll.LargeChange   = Math.Max(largeChange.Height, smallChange.Height);

            var size = Hexgrid.GetSize(MapSizePixels, MapScale);

            if (AutoScrollMinSize != size)
            {
                AutoScrollMinSize        = size;
                HorizontalScroll.Maximum = Math.Min(1, Math.Max(1, Padding.Left + Padding.Right
                                                                + size.Width - ClientSize.Width));
                VerticalScroll.Maximum = Math.Min(1, Math.Max(1, Padding.Top + Padding.Bottom
                                                              + size.Height - ClientSize.Height));
                Invalidate();
            }
        }
示例#16
0
        /// <summary>
        /// Returns a Red on Black bitmap from a String
        /// no trimming is applied
        /// </summary>
        /// <param name="font">The font to use</param>
        /// <param name="s">The string to paint</param>
        /// <returns></returns>
        private Bitmap GetStringBitmap(Font font, String s)
        {
            // get the size needed to paint the string in one line with the font given
            Bitmap       fontImage       = new Bitmap(1600, 200);// biggg to have all printed on one line which is needed for long strings and large fonts
            Graphics     g               = Graphics.FromImage(fontImage);
            StringFormat newStringFormat = new StringFormat();

            newStringFormat.Alignment     = StringAlignment.Near;
            newStringFormat.LineAlignment = StringAlignment.Near;
            newStringFormat.Trimming      = StringTrimming.None;
            Size preferredSize = Size.Ceiling(g.MeasureString(s, font, new Size(1600, 200), newStringFormat));

            g.Dispose( );

            // get a new bitmap with optimal size for painting stuff
            fontImage = new Bitmap(preferredSize.Width, preferredSize.Height);
            g         = Graphics.FromImage(fontImage);
            g.ResetClip( );
            g.Clear(Color.Black);
            // set text drawing props to make the best capturing later
            g.TextContrast      = 0;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            g.DrawString(s, font, Brushes.Red, new Point(0, 0));   // draw red on black for capturing
            g.Flush(System.Drawing.Drawing2D.FlushIntention.Sync); // get things finished
            g.Dispose( );

            //fontImage.Save( "TEST.png" ); // save the temp result
            return(fontImage);
        }
示例#17
0
        /// <include file='doc\GroupLabel.uex' path='docs/doc[@for="GroupLabel.OnPaint"]/*' />
        /// <devdoc>
        ///    Custom UI is painted here
        /// </devdoc>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics  g    = e.Graphics;
            Rectangle r    = ClientRectangle;
            string    text = Text;

            Brush foreBrush = new SolidBrush(ForeColor);

            g.DrawString(text, Font, foreBrush, 0, 0);
            foreBrush.Dispose();

            int etchLeft = r.X;

            if (text.Length != 0)
            {
                Size sz = Size.Ceiling(g.MeasureString(text, Font));
                etchLeft += 4 + sz.Width;
            }
            int etchTop = r.Height / 2;

            g.DrawLine(SystemPens.ControlDark, etchLeft, etchTop, r.Width, etchTop);

            etchTop++;
            g.DrawLine(SystemPens.ControlLightLight, etchLeft, etchTop, r.Width, etchTop);
        }
        /// <summary>Set ScrollBar increments and bounds from map dimensions.</summary>
        public virtual void SetScrollLimits(IMapDisplay model)
        {
            if (model == null || !AutoScroll)
            {
                return;
            }
            var smallChange = Size.Ceiling(model.GridSize.Scale(MapScale));

            HorizontalScroll.SmallChange = smallChange.Width;
            VerticalScroll.SmallChange   = smallChange.Height;

            var largeChange = Size.Round(ClientSize.Scale(0.75F));

            HorizontalScroll.LargeChange = Math.Max(largeChange.Width, smallChange.Width);
            VerticalScroll.LargeChange   = Math.Max(largeChange.Height, smallChange.Height);

            var size = DataContext.Hexgrid.GetSize(MapSizePixels, MapScale)
                       + Margin.Size;

            if (AutoScrollMinSize != size)
            {
                AutoScrollMinSize        = size;
                HorizontalScroll.Maximum = Math.Min(1, Math.Max(1, Margin.Horizontal
                                                                + size.Width - ClientSize.Width));
                VerticalScroll.Maximum = Math.Min(1, Math.Max(1, Margin.Vertical
                                                              + size.Height - ClientSize.Height));
                Invalidate();
            }
        }
        internal int GetContentsWidth(bool newPanel)
        {
            string text;

            if (newPanel)
            {
                if (this.text == null)
                {
                    text = "";
                }
                else
                {
                    text = this.text;
                }
            }
            else
            {
                text = this.Text;
            }
            Graphics graphics = this.parent.CreateGraphicsInternal();
            Size     size     = Size.Ceiling(graphics.MeasureString(text, this.parent.Font));

            if (this.icon != null)
            {
                size.Width += this.icon.Size.Width + 5;
            }
            graphics.Dispose();
            int num = ((size.Width + (SystemInformation.BorderSize.Width * 2)) + 6) + 2;

            return(Math.Max(num, this.minWidth));
        }
示例#20
0
        public void DrawDebugInto(Graphics g, PointF location)
        {
            Matrix orgM = g.Transform;
            Matrix newM = orgM.Clone();

            newM.Translate(location.X, location.Y, MatrixOrder.Append);
            g.Transform = newM;

            Vex.Matrix m    = GetMatrix();
            string     text = "i: " + instance.InstanceHash + " d: " + instance.DefinitionId + " dp: " + instance.Depth + "\n";

            text += "loc: " + Location.X.ToString("F2") + " : " + Location.Y.ToString("F2") + "\n";
            text += "mx: " +
                    m.ScaleX.ToString("F2") + ", " +
                    m.Rotate0.ToString("F2") + ", " +
                    m.Rotate1.ToString("F2") + ", " +
                    m.ScaleY.ToString("F2") + "\n";

            SizeF sz = g.MeasureString(text, SystemFonts.DefaultFont);

            Point loc = new Point((int)(-sz.Width / 2), (int)(-sz.Height / 2));

            g.FillRectangle(debugBkg, new Rectangle(loc, Size.Ceiling(sz)));
            g.DrawString(text, SystemFonts.DefaultFont, Brushes.DarkRed, loc);

            g.Transform = orgM;
            newM.Dispose();
        }
示例#21
0
        public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination)
        {
            var context = graphics.Control;

            context.Save();
            context.Rectangle(destination.ToCairo());
            double scalex = 1;
            double scaley = 1;
            var    pb     = Widget.GetFrame(1, Size.Ceiling(destination.Size));

            if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f)
            {
                scalex  = (double)destination.Width / (double)source.Width;
                scaley  = (double)destination.Height / (double)source.Height;
                scalex *= (double)Size.Width / (double)pb.PixelSize.Width;
                scaley *= (double)Size.Height / (double)pb.PixelSize.Height;
                context.Scale(scalex, scaley);
            }
            Gdk.CairoHelper.SetSourcePixbuf(context, pb.Bitmap.ToGdk(), (destination.Left / scalex) - source.Left, (destination.Top / scaley) - source.Top);
            var pattern = (Cairo.SurfacePattern)context.GetSource();

            pattern.Filter = graphics.ImageInterpolation.ToCairo();
            context.Fill();
            context.Restore();
            pattern.Dispose();
        }
示例#22
0
        void CalculateTab(ThemedDocumentPageHandler tab, int i, ref float posx)
        {
            var textSize    = string.IsNullOrEmpty(tab.Text) ? Size.Empty : Size.Ceiling(Font.MeasureString(tab.Text));
            var size        = textSize;
            var prevnextsel = mousePos.X > nextPrevWidth || i == -1;
            var textoffset  = 0;

            if (tab.Image != null)
            {
                textoffset  = tab.Image.Size.Width + TabPadding.Left;
                size.Width += textoffset;
            }

            var closesize = tabDrawable.Height / 2;
            var tabRect   = new RectangleF(posx, 0, size.Width + (tab.Closable ? closesize + TabPadding.Horizontal + TabPadding.Right : TabPadding.Horizontal), tabDrawable.Height);

            if (i == selectedIndex && draggingLocation != null)
            {
                tabRect.Offset(mousePos.X - draggingLocation.Value.X, 0);
            }

            tab.Rect = tabRect;

            tab.CloseRect = new RectangleF(tabRect.X + tab.Rect.Width - tabDrawable.Height / 4 - closesize, tabDrawable.Height / 4, closesize, closesize);
            tab.TextRect  = new RectangleF(tabRect.X + TabPadding.Left + textoffset, (tabDrawable.Height - size.Height) / 2, textSize.Width, textSize.Height);

            posx += tab.Rect.Width;
        }
示例#23
0
        /// <summary>
        /// Draws the given caption and text inside the given rectangle.
        /// </summary>
        internal static int DrawStringPair(Graphics g, Rectangle r, string caption, string text, Font font, Brush captionBrush, Brush textBrush)
        {
            using (StringFormat sf = new StringFormat())
            {
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Near;
                sf.Trimming      = StringTrimming.EllipsisCharacter;
                sf.FormatFlags   = StringFormatFlags.NoWrap;

                SizeF szc = g.MeasureString(caption, font, r.Size, sf);
                int   y   = (int)szc.Height;
                if (szc.Width > r.Width)
                {
                    szc.Width = r.Width;
                }
                Rectangle txrect = new Rectangle(r.Location, Size.Ceiling(szc));
                g.DrawString(caption, font, captionBrush, txrect, sf);
                txrect.X    += txrect.Width;
                txrect.Width = r.Width;
                if (txrect.X < r.Right)
                {
                    SizeF szt = g.MeasureString(text, font, r.Size, sf);
                    y      = Math.Max(y, (int)szt.Height);
                    txrect = Rectangle.Intersect(r, txrect);
                    g.DrawString(text, font, textBrush, txrect, sf);
                }

                return(y);
            }
        }
示例#24
0
        protected Size GetLabelSize(TreeNodeAdv node, DrawContext context, string label)
        {
            PerformanceAnalyzer.Start("GetLabelSize");
            CheckThread();
            Font font = GetDrawingFont(node, context, label);
            Size s    = Size.Empty;

            if (UseCompatibleTextRendering)
            {
                s = TextRenderer.MeasureText(label, font);
            }
            else
            {
                SizeF sf = context.Graphics.MeasureString(label, font);
                s = Size.Ceiling(sf);
            }
            PerformanceAnalyzer.Finish("GetLabelSize");

            if (!s.IsEmpty)
            {
                return(s);
            }
            else
            {
                return(new Size(10, Font.Height));
            }
        }
示例#25
0
        private Size[] MeasureSize(Graphics g, ChartLegendItem[] items, int textcols)
        {
            Size[]   itemsize = new Size[textcols];
            string[] itemText;
            for (int j = 0; j < textcols; j++)
            {
                Size itemsize1 = new Size(0, 0);
                foreach (ChartLegendItem item in items)
                {
                    if (item.Visible)
                    {
                        itemText = item.Text.Split('-');
                        if (itemText.Length > j)
                        {
                            SizeF sz = GetSize(g, itemText[j], item.Font);// g.MeasureString(itemText[j], item.Font);

                            itemsize1.Width  = Math.Max((int)sz.Width, itemsize1.Width);
                            itemsize1.Height = Math.Max((int)sz.Height, itemsize1.Height);
                        }
                    }
                }
                //Set max size for desc and values separatly in itemsize array
                itemsize[j] = Size.Ceiling(itemsize1);
            }

            return(itemsize);
        }
示例#26
0
        ///////////////////////////////////////////////////////////////////////////
        // Event Handlers

        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics     g      = e.Graphics;
            Rectangle    r      = ClientRectangle;
            StringFormat format = new StringFormat();
            string       text   = Text;

            Brush foreBrush = new SolidBrush(ForeColor);

            format.HotkeyPrefix  = HotkeyPrefix.Show;
            format.LineAlignment = StringAlignment.Center;
            g.DrawString(text, Font, foreBrush, r, format);
            foreBrush.Dispose();

            int etchLeft = r.X;

            if (text.Length != 0)
            {
                Size sz = Size.Ceiling(g.MeasureString(text, Font, new Size(0, 0), format));
                etchLeft += 4 + sz.Width;
            }
            int etchTop = r.Height / 2;

            g.DrawLine(SystemPens.ControlDark, etchLeft, etchTop, r.Width, etchTop);

            etchTop++;
            g.DrawLine(SystemPens.ControlLightLight, etchLeft, etchTop, r.Width, etchTop);

            format.Dispose();
        }
示例#27
0
        public override void Draw(Graphics graphics)
        {
            base.DrawBackground(graphics);
            if (this.Image != null)
            {
                ImageAttributes ImgAtt = new ImageAttributes();
                ImgAtt.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Clamp);
                var fontSize = Size.Ceiling(graphics.MeasureString(this.Text, this.Font));
                var x        = (this.Width - fontSize.Width - 4 - this.ImageSize.Width) / 2;//图片与文字间隔4个像素
                var y        = (this.Height - ImageSize.Height) / 2;

                var rec = new Rectangle(this.X + x, this.Y + y, this.ImageSize.Width, this.ImageSize.Height);
                graphics.DrawImage(this.Image, rec, 0, 0, this.Image.Width, this.Image.Height, GraphicsUnit.Pixel, ImgAtt);
                x += ImageSize.Width + 4;
                using (var brush = new SolidBrush(this.ForeColor))
                {
                    graphics.DrawString(this.Text, this.Font, brush, x + this.X, (this.Height - fontSize.Height) / 2);
                }
            }

            if (this.Notify != null)
            {
                this.Notify.Draw(graphics);
            }
        }
示例#28
0
        public static Size NodeSize(StringFormat sf, Font f, Graphics g, string text, Size minSize, Size maxSize)
        {
            var size = Size.Ceiling(g.MeasureString(text, f, maxSize, sf));

            size += new Size(2, 2); // focus
            return(new Size(Math.Max(size.Width, minSize.Width) + 2, Math.Max(size.Height, minSize.Height)));
        }
示例#29
0
        public static Size GetLeftHandSideTipSize(Control control, Graphics graphics, TipSection tipData, Point p)
        {
            var tipSize = Size.Empty;

            RectangleF workingArea = GetWorkingArea(control);

            PointF screenLocation = p;

            var maxLayoutSize = new SizeF(
                screenLocation.X - HorizontalBorder * 2,
                workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);

            if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0)
            {
                graphics.TextRenderingHint =
                    TextRenderingHint.AntiAliasGridFit;

                tipData.SetMaximumSize(maxLayoutSize);
                var tipSizeF = tipData.GetRequiredSize();
                tipData.SetAllocatedSize(tipSizeF);

                tipSizeF += new SizeF(
                    HorizontalBorder * 2,
                    VerticalBorder * 2);
                tipSize = Size.Ceiling(tipSizeF);
            }

            return(tipSize);
        }
示例#30
0
        public void DrawImage(Image image, float x, float y, float width, float height)
        {
            SetOffset(true);
            var bmp = image.ToDx(Control, Size.Ceiling(CurrentTransform.TransformSize(new SizeF(width, height))));

            Control.DrawBitmap(bmp, new s.RectangleF(x, y, width, height), 1f, ImageInterpolation.ToDx());
        }