MeasureString() публичный метод

public MeasureString ( string text, Font font ) : SizeF
text string
font Font
Результат SizeF
        public override void Draw(Graphics g, Pen p)
        {
            base.Draw(g, p);

            var r = this.RectangleF;

            var sText = g.MeasureString(this.ColouredPlace.ColorSetName, new Font("Arial", 8));
            g.FillRectangle(Brushes.Gray, r.Right, r.Top - sText.Height, sText.Width, sText.Height);

            g.DrawString(
                this.ColouredPlace.ColorSetName,
                new Font("Arial", 8),
                Brushes.Blue,
                r.Right,
                r.Top - sText.Height
            );

            var tokensString = this.ColouredPlace.Tokens.ToString();
            var f = new Font("", 7);
            sText = g.MeasureString(tokensString, f);

            g.FillRectangle(Brushes.Green, r.Right, r.Bottom, sText.Width, sText.Height);
            g.DrawString(
                tokensString,
                new Font("", 7),
                Brushes.Black,
                r.Right,
                r.Bottom
            );
        }
Пример #2
1
        public void PaintJunk(Graphics g)
        {
            g.FillRectangle(Brushes.Transparent, 0, 0, 1000, 1000);

            using (Font font = new Font("Courier New", 20, FontStyle.Bold))
            {
                if (bounceCounter == -1) return;
                const string str = "DEVELOPER BUILD";
                float x = 0;
                int timefactor = bounceCounter;
                for (int i = 0; i < str.Length; i++)
                {
                    string slice = str.Substring(i, 1);
                    g.PageUnit = GraphicsUnit.Pixel;
                    x += g.MeasureString(slice, font).Width - 1;

                    int offset = -i * 3 + timefactor*3;
                    int yofs = 0;
                    if (offset < 0)
                    { continue; }
                    else
                        if (offset < DigitTable.Length)
                            yofs = DigitTable[offset];
                    g.DrawString(slice, font, Brushes.Black, 5 + x, 15 - yofs);
                }
            }
        }
Пример #3
0
        public static void DrawParallelEdgeSelected(Graphics g, IEdge e, IEnumerable<IEdge> es, Font f, PointF pSource, PointF pTarget, int Radius = 5)
        {
            var ps = pSource;
            var pt = pTarget;
            String s = "";
            List<float> Heights = new List<float>();
            foreach (var et in es)
            {
                string str = et.AttributesToString();
                s += str;
                Heights.Add(g.MeasureString(str, f).Height);
            }

            SizeF size = g.MeasureString(s, f);
            PointF location = new PointF((pt.X * 2 + 3 * ps.X) / 5 - 4, (pt.Y * 2 + ps.Y * 3) / 5 - 4);
            RectangleF rect = new RectangleF(location, size);
            GraphicsPath roundedRect = GetRoundedRect(rect, Radius);

            g.DrawLine(penHover, ps, pt);
            g.FillEllipse(brushHover, (pt.X + ps.X) / 2 - 2, (pt.Y + ps.Y) / 2 - 2, 4, 4);

            float hM = -1;

            g.FillPath(brushAttrPanel, roundedRect);

            foreach (var h in Heights)
            {
                hM += h;
                g.DrawLine(penAttrBorderSlipt, location.X + Radius, location.Y + hM, location.X + size.Width - Radius, location.Y + hM);
            }

            g.DrawPath(penAttrBorder, roundedRect);

            g.DrawString(s, f, brushText, rect);
        }
Пример #4
0
		/// <summary>
		/// </summary>
		/// <param name="graphics"></param>
		/// <param name="bounds"></param>
		/// <param name="min"></param>
		/// <param name="max"></param>
		public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
		{
			if (Bars == null)
				return;

			// Recalculate the proper string size should the chart control object font and axis color change
			if (textBrush.Color != ChartControl.AxisColor || textFont != ChartControl.Font)
			{
				textBrush.Color = ChartControl.AxisColor;
				textFont = (Font) ChartControl.Font.Clone();

				SizeF size = graphics.MeasureString((CountDown ? "Volume remaining = %" : "Volume count = %") + Bars.Period.Value, textFont);
				textWidth		= size.Width + 5;
				textHeight		= size.Height + 5;

				SizeF noTickSize = graphics.MeasureString(errorText, textFont);
				noTickTextWidth = noTickSize.Width + 5;
				noTickTextHeight = noTickSize.Height + 5;
			}

			// Plot the volume count message to the lower right hand corner of the chart
			if (Bars.Period.Id == PeriodType.Volume)
			{
				double volumeCount = ShowPercent ? CountDown ? (1 - Bars.PercentComplete) * 100 : Bars.PercentComplete * 100 : CountDown ? Bars.Period.Value - volume : volume;
				graphics.DrawString((CountDown ? " Volume remaining = " + volumeCount : "Volume = " + volumeCount) + (ShowPercent ? "%" : ""), ChartControl.Font, textBrush, bounds.X + bounds.Width - textWidth, bounds.Y + bounds.Height - textHeight, stringFormat);
			}
			else
				graphics.DrawString(errorText, ChartControl.Font, textBrush, bounds.X + bounds.Width - noTickTextWidth, bounds.Y + bounds.Height - noTickTextHeight, stringFormat);
		}
Пример #5
0
    protected override void _DrawItem(Graphics g, int index, int y)
    {
      //base._DrawItem(g,  index,  y);      return;

      //this._Broker.LoadItem(index);
      _Broker.Index = index;
      BookItem item = _Broker.Current;
      int x = 4;
      g.DrawRectangle(this._PenBorder, x, y, _Width - 2 * x, this._ItemHeight);
      g.FillRectangle(Brushes.Khaki, x + 1, y + 1, _Width - 2 * x-1, this._ItemHeight-1);

      x += 3;
      g.DrawString(item.Author, this._FontAutor , Brushes.Black, x, y);

      SizeF size = g.MeasureString(item.Author, this._FontAutor);
      x += (int)size.Width + 20;
      g.DrawString(item.Title, this._FontTitle, Brushes.Blue, x, y);

      size = g.MeasureString(item.Author, this._FontTitle);
      if (index == this._SelectedIndex)
      {
        g.FillEllipse(Brushes.WhiteSmoke, _Width - 35, y + 5, 20, 20);
        g.DrawEllipse(this._PenBorder, _Width - 35, y + 5, 20, 20);
      }
    }
		/// <summary>
		/// Replaces the trailer symbols of the specified line with "...".
		/// </summary>		
		private string EaterSubRoutine(string stringToTrim, Font stringFont, float maxLength, Graphics grfx)
		{
			Debug.Assert(stringFont != null, "stringFont != null");
			Debug.Assert(grfx != null, "grfx != null");

			if (stringToTrim == null)
			{
				return "";
			}

			if (maxLength <= grfx.MeasureString(EAT_TRAILER, stringFont).Width)
				return "";

			// Maybe the input string is already of necessary length.
			if (grfx.MeasureString(stringToTrim, stringFont).Width < maxLength)
			{
				return stringToTrim;
			}
			else
			{
				if (stringToTrim.Length < 4)
					stringToTrim = "";
				else
					stringToTrim = stringToTrim.Remove(stringToTrim.Length - 4, 1);

				return this.EaterSubRoutine(stringToTrim, stringFont, maxLength, grfx);
			}
		}
Пример #7
0
        public static PointF GetPointForCenterString(Graphics graphics, Rectangle rectangle, string Message, Font font, int margin, string spacer, out string formatedMessage)
        {
            SizeF size = graphics.MeasureString(Message, font);

            if (size.Width > rectangle.Width - margin)
            {
                StringBuilder resultStr = new StringBuilder(Message.Length + spacer.Length);
                resultStr.Append(Message);
                while ((resultStr.Length > 0) && (size.Width > rectangle.Width - margin))
                {
                    resultStr = resultStr.Remove(resultStr.Length - 1, 1);
                    size = graphics.MeasureString(resultStr.ToString() + spacer, font);
                }

                if (resultStr.Length > 0)
                {
                    formatedMessage = resultStr.ToString() + spacer;
                    return new PointF(margin, rectangle.Height / 2);
                }
                else
                {
                    formatedMessage = string.Empty;
                    return PointF.Empty;
                }
            }
            else
            {
                formatedMessage = Message;
                return new PointF((rectangle.Width / 2) - (size.Width / 2), (rectangle.Height / 2) - (font.SizeInPoints / 2));
            }
        }
Пример #8
0
        public static Font AppropriateFont(Graphics g, Size layoutSize, string s, Font f, out SizeF extent)
        {
            //if (maxFontSize == minFontSize)
            //    f = new Font(f.FontFamily, minFontSize, f.Style);

            extent = g.MeasureString(s, f);

            //if (maxFontSize <= minFontSize)
            //    return f;

            float hRatio = layoutSize.Height / extent.Height;
            float wRatio = layoutSize.Width / extent.Width;
            float ratio = (hRatio < wRatio) ? hRatio : wRatio;

            float newSize = f.Size * ratio;

            //if (newSize < minFontSize)
            //    newSize = minFontSize;
            //else if (newSize > maxFontSize)
            //    newSize = maxFontSize;

            f = new Font(f.FontFamily, newSize, f.Style);
            extent = g.MeasureString(s, f);

            return f;
        }
Пример #9
0
		/// <summary>
		/// </summary>
		/// <param name="graphics"></param>
		/// <param name="bounds"></param>
		/// <param name="min"></param>
		/// <param name="max"></param>
		public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
		{
			if (Bars == null)
				return;

			// Recalculate the proper string size should the chart control object font and axis color change
			if (textBrush.Color != ChartControl.AxisColor || textFont != ChartControl.Font)
			{
				textBrush.Color = ChartControl.AxisColor;
				textFont = (Font) ChartControl.Font.Clone();

				SizeF size = graphics.MeasureString((CountDown ? "Ticks remaining = %" : "Tick count = %") + Bars.Period.Value, textFont);
				textWidth		= size.Width + 5;
				textHeight		= size.Height + 5;

				SizeF noTickSize = graphics.MeasureString(errorTick, textFont);
				noTickTextWidth = noTickSize.Width + 5;
				noTickTextHeight = noTickSize.Height + 5;
			}

			// Plot the tick count message to the lower right hand corner of the chart
			if (Bars.Period.Id == PeriodType.Tick || (Bars.Period.BasePeriodType == PeriodType.Tick 
				&& Bars.Period.Id != PeriodType.PointAndFigure && Bars.Period.Id != PeriodType.Kagi && Bars.Period.Id != PeriodType.LineBreak))
			{
				int		periodValue	= (Bars.Period.Id == PeriodType.Tick) ? Bars.Period.Value : Bars.Period.BasePeriodValue;
				double	tickCount	= ShowPercent ? CountDown ? (1 - Bars.PercentComplete) * 100 : Bars.PercentComplete * 100 : CountDown ? periodValue - Bars.TickCount : Bars.TickCount;
				graphics.DrawString((CountDown ? " Ticks remaining = " + tickCount : "Tick count = " + tickCount) + (ShowPercent ? "%" : ""), ChartControl.Font, textBrush, bounds.X + bounds.Width - textWidth, bounds.Y + bounds.Height - textHeight, stringFormat);
			}
			else
				graphics.DrawString(errorTick, ChartControl.Font, textBrush, bounds.X + bounds.Width - noTickTextWidth, bounds.Y + bounds.Height - noTickTextHeight, stringFormat);
		}
Пример #10
0
        public override SizeF Measure(Graphics graphics)
		{
			if (!string.IsNullOrWhiteSpace(this.Text))
			{
				if (this.TextSize.IsEmpty)
				{
					var size = new Size(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);

					if (this.Input.Enabled != this.Output.Enabled)
					{
						if (this.Input.Enabled)
							this.TextSize = graphics.MeasureString(this.Text, SystemFonts.MenuFont, size, GraphConstants.LeftMeasureTextStringFormat);
						else
							this.TextSize = graphics.MeasureString(this.Text, SystemFonts.MenuFont, size, GraphConstants.RightMeasureTextStringFormat);
					} else
						this.TextSize = graphics.MeasureString(this.Text, SystemFonts.MenuFont, size, GraphConstants.CenterMeasureTextStringFormat);

					this.TextSize.Width  = Math.Max(size.Width, this.TextSize.Width);
					this.TextSize.Height = Math.Max(size.Height, this.TextSize.Height);
				}
				return this.TextSize;
			} else
			{
				return new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
			}
		}
Пример #11
0
        public RenderData CreateRenderData(Graph graph, Graphics g, int width, int height)
        {
            RenderData data = new RenderData
            {
                Graph = graph,
                g = g,
                Width = width,
                Height = height,
                AxisPen = new Pen(Color.Black),
                AxisFont = new Font(FontFamily.GenericSansSerif, 10.0f),
                AxisBrush = new SolidBrush(Color.Black),
                AxisStringFormat = "#,##0.##",
                LegendFont = new Font(FontFamily.GenericSansSerif, 10.0f),
                LegendBrush = new SolidBrush(Color.Black),
                LargeTickLength = 10,
                SeriesPens = graph.Series.Select(s => new Pen(s.Color)).ToArray()
            };

            data.LegendFontMetrics = g.MeasureString("Title of a Series", data.LegendFont);
            int legendWidth = (int)(data.LegendFontMetrics.Width + 20);
            data.LegendRect = new Rectangle(width - legendWidth, 0, legendWidth, height);

            SizeF axisFontMetrics = g.MeasureString(graph.ActualYMaximum.ToString(data.AxisStringFormat), data.AxisFont);
            data.AxisYRect = new Rectangle(0, 0, (int)(axisFontMetrics.Width + data.LargeTickLength), (int)(height - axisFontMetrics.Height - data.LargeTickLength));
            data.AxisXRect = new Rectangle(data.AxisYRect.Right, data.AxisYRect.Bottom, width - data.AxisYRect.Left - data.LegendRect.Width, (int)(axisFontMetrics.Height + data.LargeTickLength));
            data.GraphRect = new Rectangle(data.AxisYRect.Right, data.AxisYRect.Top, width - data.AxisYRect.Width - data.LegendRect.Width,
                                           height - data.AxisYRect.Top - data.AxisXRect.Height);

            data.XMin = data.Graph.ActualXMinimum;
            data.XMax = data.Graph.ActualXMaximum;
            data.XInterval = data.Graph.ActualXInterval;
            if (Math.Abs(data.XMax - data.XMin) < 0.0001)
            {
                data.XPixelInterval = width / 10.0;
                data.XPixelsPerValue = 0.0;
            }
            else
            {
                data.XPixelInterval = Math.Max(1.0, data.GraphRect.Width / ((data.XMax - data.XMin) / data.XInterval));
                data.XPixelsPerValue = data.GraphRect.Width / (data.XMax - data.XMin);
            }

            data.YMin = data.Graph.ActualYMinimum;
            data.YMax = data.Graph.ActualYMaximum;
            data.YInterval = data.Graph.ActualYInterval;
            if (Math.Abs(data.YMax - data.YMin) < 0.0001)
            {
                data.YPixelInterval = height / 10.0;
                data.YPixelsPerValue = 0.0;
            }
            else
            {
                data.YPixelInterval = Math.Max(1.0, data.GraphRect.Height / ((data.YMax - data.YMin) / data.YInterval));
                data.YPixelsPerValue = data.GraphRect.Height / (data.YMax - data.YMin);
            }

            return data;
        }
Пример #12
0
 public static SizeF DrawNamedValue( Graphics g, string name, string value, Font font, PointF point )
 {
     string _name = name + ": ";
     SizeF size1 = g.MeasureString( _name, font );
     g.DrawString( _name, font, Brushes.Gray, point );
     SizeF size2 = g.MeasureString( value, font );
     g.DrawString( value, new Font( font, FontStyle.Bold ), Brushes.Black, point.X + size1.Width, point.Y );
     return new SizeF( size1.Width + size2.Width, Math.Max( size1.Height, size2.Height ) );
 }
Пример #13
0
        /// <summary>
        /// Analyzes UI for display. Assumes ideal height for provided width wihtout invalidating or painting.
        /// </summary>
        /// <param name="g">A Graphics object used for measurements.</param>
        /// <param name="width">Control's width.</param>
        public void Analyze(Graphics g, int width)
        {
            bool isTextPoolNew = textPool == null;

            // If width or script has not changed, nothing to do.
            if (analyzedWidth == width) return;
            analyzedWidth = Width;
            positionedBlocks = null;
            targetHiliteIndexes = null;

            // This is how we measure
            StringFormat sf = StringFormat.GenericTypographic;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            // On-demand: measure a space's width - for entry text flow
            // Also line height in entry text
            if (spaceWidth == 0)
            {
                SizeF sz = g.MeasureString(spaceTestStr, getFont(fntSenseLatin), 65535, sf);
                spaceWidth = (int)sz.Width;
                lemmaCharHeight = sz.Height;
                lemmaLineHeight = sz.Height * Magic.LemmaLineHeightScale;
                sz = g.MeasureString(Magic.PinyinSpaceTestString, getFont(fntPinyinHead), 65535, sf);
                pinyinSpaceWidth = sz.Width;
            }

            // Create text pool if needed
            if (textPool == null) textPool = new TextPool();

            // Headword and pinyin
            // Will not measure redundantly
            doAnalyzeHeadword(g);
            doAnalyzePinyin(g);

            // OK, now onto body
            // Measure blocks in themselves on demand
            // Will not measure redundantly
            doMeasureBlocks(g);

            // Finalize text pool - compact in memory
            if (isTextPoolNew) textPool.FinishBuilding();
            // Get rid of entry. Not keeping it in memory once we're done analyzing.
            entry = null;

            // Arrange blocks
            float lemmaW = ((float)width) - headInfo.HeadwordRight - padMid - padRight;
            float lemmaL = headInfo.HeadwordRight + padMid;
            float lastTop = doArrangeBlocks(lemmaL, lemmaW);

            // My height: bottom of headword or bottom of entry, whichever is lower
            float entryHeight = lastTop + padBottom;
            float zhoHeight = headInfo.HeadwordBottom + padBottom;
            float trueHeight = Math.Max(entryHeight, zhoHeight);

            // Assume this height, and also provided width
            Size = new Size(width, (int)trueHeight);
        }
Пример #14
0
        public override void Draw(Graphics g, GraphPane pane)
        {
            SizeF size;
            PointF pos;
            float x, y1, y2, y3;
            string label;

            //Draw Axis Title
            if (mTitle.Visible) {
                using (Brush brush = new SolidBrush(mTitle.Color)) {
                    if (mTitle.Orientation == Orientation.Vertical) {
                        g.RotateTransform(-90);
                        g.TranslateTransform(-mPane.ClientRectangle.Height, 0);
                        size = g.MeasureString(mTitle.Text, mTitle.Font);
                        pos = new PointF(mTitle.Padding, mRect.Left + mRect.Width / 2 - size.Height / 2);
                        g.DrawString(mTitle.Text, mTitle.Font, brush, pos);
                        g.ResetTransform();
                    } else {
                        size = g.MeasureString(mTitle.Text, mTitle.Font);
                        pos = new PointF(mRect.Left + (mRect.Width / 2 - size.Width / 2), mRect.Top + mTitle.Padding);
                        if (mLabels.Visible) pos.Y += (mLabels.Font.Height + (mLabels.Padding * 2));
                        g.DrawString(mTitle.Text, mTitle.Font, brush, pos);

                    }
                }
            }

            //Draw Minor Gridlines and Marks
            y1 = mRect.Top - mMinorMark.Size;
            y2 = mRect.Top;
            for (double dx = Minimum; dx <= Maximum; dx += mMinorStep) {
                x = mRect.X + (float)((dx - mMinimum) * mScale);
                if (mMinorMark.Visible) g.DrawLine(mMinorMark.Pen, x, y1, x, y2);
            }

            //Draw Major Gridlines, Marks and Labels
            y1 = mRect.Top - mMajorMark.Size;
            y2 = mRect.Top;
            y3 = y2 + mLabels.Padding;
            using (Brush b = new SolidBrush(mLabels.Color)) {
                for (double dx = Minimum; dx <= Maximum; dx += mMajorStep) {
                    x = mRect.X + (float)((dx - mMinimum) * mScale);
                    if (mMajorMark.Visible) g.DrawLine(mMajorMark.Pen, x, y1, x, y2);
                    if (mLabels.Visible) {
                        label = FormatLabel(dx);
                        size = g.MeasureString(label, mLabels.Font);
                        x = x - size.Width / 2;
                        if (mPane.ClientRectangle.Contains(x, y3) && mPane.ClientRectangle.Contains(x + size.Width, y3 + size.Height))
                            g.DrawString(label, mLabels.Font, b, x, y3);
                    }
                }
            }

            //Draw The Axis
            g.DrawLine(mPen, mRect.Left, mRect.Top, mRect.Right, mRect.Top);
        }
Пример #15
0
	public SBGE(GrapherParams cgp, Graphics gr, bool fWgtAvg)
	{
		m_cgp = cgp;
		m_fWgtAvg = fWgtAvg;

		Font font = new Font("Tahoma", 8);

		m_dxOffset = gr.MeasureString("0000", font).Width;
		m_dyOffset = gr.MeasureString("0\n0\n0\n0\n", font).Height;
	}
Пример #16
0
 public void Draw(Graphics g)
 {
     Font font = new Font("Helvetica", Priority * 7, FontStyle.Italic);
     Brush brush = new SolidBrush(System.Drawing.Color.Black);
     if (Activity != true)
         brush = new SolidBrush(System.Drawing.Color.Green);
     g.DrawString(TaskName, font, brush, xValue, yValue);
     Height = g.MeasureString(TaskName, font).Height;
     Width = g.MeasureString(TaskName, font).Width;
 }
Пример #17
0
        public override void Draw(Graphics g, GraphPane pane)
        {
            SizeF size;
            PointF pos;
            float y, x1, x2, x3;
            string label;

            //Draw Axis Title
            if (mTitle.Visible) {
                using (Brush b = new SolidBrush(mTitle.Color)) {
                    if (mTitle.Orientation == Orientation.Vertical) {
                        g.RotateTransform(-90);
                        g.TranslateTransform(-mRect.Height, 0);
                        size = g.MeasureString(mTitle.Text, mTitle.Font);
                        pos = new PointF(mRect.Height / 2 - size.Width / 2, mRect.Left + mTitle.Padding);
                        g.DrawString(mTitle.Text, mTitle.Font, b, pos);
                        g.ResetTransform();
                    } else {
                        size = g.MeasureString(mTitle.Text, mTitle.Font);
                        pos = new PointF(mRect.Left + mTitle.Padding, mRect.Height / 2 - size.Width / 2);
                        g.DrawString(mTitle.Text, mTitle.Font, b, pos);
                    }
                }
            }

            //Draw Minor Grid and Mark
            x1 = mRect.Right + mMinorMark.Size;
            x2 = x1 - mMinorMark.Size;
            for (double dy = Minimum; dy < Maximum; dy += mMinorStep) {
                y = mRect.Bottom - (float)((dy - mMinimum) * mScale);
                if (mMinorMark.Visible) g.DrawLine(mMinorMark.Pen, x1, y, x2, y);
            }

            //Draw Major Gridlines, Marks and Labels
            x1 = mRect.Right + mMajorMark.Size;
            x2 = x1 - mMajorMark.Size;

            using (Brush b = new SolidBrush(mLabels.Color)) {
                for (double dy = Minimum; dy <= Maximum; dy += mMajorStep) {
                    y = mRect.Bottom - (float)((dy - mMinimum) * mScale);
                    if (mMajorMark.Visible) g.DrawLine(mMajorMark.Pen, x1, y, x2, y);
                    if (mLabels.Visible) {
                        label = dy.ToString(mLabels.Format);
                        size = g.MeasureString(label, mLabels.Font);
                        y = y - size.Height / 2;
                        x3 = x2 - (size.Width + mLabels.Padding);
                        if (mPane.ClientRectangle.Contains(x3, y) && mPane.ClientRectangle.Contains(x3, y + size.Height))
                            g.DrawString(label, mLabels.Font, b, x3, y);
                    }
                }
            }

            //Draw The Axis
            g.DrawLine(mPen, mRect.Right, mRect.Top, mRect.Right, mRect.Bottom);
        }
        public override System.Drawing.SizeF MeasureItem(System.Drawing.Graphics g, System.Drawing.Font font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant mtick, System.Drawing.PointF morg)
        {
            string firstpart, exponent;

            SplitInFirstPartAndExponent((double)mtick, out firstpart, out exponent);

            SizeF size1 = g.MeasureString(firstpart, font, new PointF(0, 0), strfmt);
            SizeF size2 = g.MeasureString(exponent, font, new PointF(size1.Width, 0), strfmt);

            return(new SizeF(size1.Width + size2.Width, size1.Height));
        }
Пример #19
0
        /// <summary>
        /// Paint me
        /// </summary>
        /// <param name="g"></param>
        protected override void OnPaint(System.Drawing.Graphics g)
        {
            if (Labels.Count == 0)
            {
                return;
            }
            else if (Labels.Count == 1)
            {
                StringFormat tsf = new StringFormat();
                tsf.Alignment = StringAlignment.Center;
                //GraphicsContainer gc1 = g.BeginContainer();
                SizeF ys = g.MeasureString(Labels[0], Font, Height, tsf);
                g.RotateTransform(-90);
                g.DrawString(Labels[0], Font, new SolidBrush(ForeColor),
                             new RectangleF(new PointF(-Height, 0), new SizeF(Height, ys.Height)), tsf);
                //g.EndContainer(gc1);

//				//Add Y title height to ChControl X coordinate
//				x += (int)Math.Ceiling(ys.Height);
            }
            else if (Labels.Count > 1)
            {
                //Draw Legend
                SizeF  ys;
                double ys_height = 5.0f;
                string ly;
                int    x = 5;
                for (int i = 0; i < Labels.Count; i++)
                {
                    ly = Labels[i];

                    ys = g.MeasureString(ly, Font);

                    if (showcolors)
                    {
                        g.FillRectangle(new SolidBrush((Color)colors[i]), 10, (float)ys_height + 3, 5, ys.Height - 6);
                        x = 20;
                    }

                    g.DrawString(ly, Font, new SolidBrush(ForeColor), x, (float)ys_height);

                    if (i < Labels.Count - 1)
                    {
                        ys_height += ys.Height + margin;
                    }
                    else
                    {
                        ys_height += margin;
                    }
                }

                g.DrawRectangle(new Pen(ForeColor), 0, 0, Width - 1, Height - 1);
            }
        }
Пример #20
0
        /// <summary>
        /// 获取文字的大小及绘制位置
        /// </summary>
        /// <param string="C_Str">文字字符串</param>
        public void GetTextInfo(string C_Str)
        {
            SizeF TitSize = g.MeasureString(C_Str, Str_Font);                    //将绘制的字符串进行格式化

            Str_Width     = TitSize.Width;                                       //获取字符串的宽度
            Str_Height    = TitSize.Height;                                      //获取字符串的高度
            Str_Odd_Width = Str_Width / (float)C_Str.Length;                     //获取单个文字的宽度
            Str_Width     = (float)((Str_Odd_Width + Str_block) * C_Str.Length); //获取文字的宽度
            Str_Width     = (Panel_W - Str_Width) / 2F;                          //使文字居中
            Str_Height    = Panel_H - Str_Height;                                //使文字显示在控件底端
        }
Пример #21
0
 public void rysujSlupek(Graphics g,Rectangle aRozmiar, String aTekstGora, String aTekstDol)
 {
     g.FillRectangle(pedzelGreen,aRozmiar);
     Font f1 = new Font("Arial",6,FontStyle.Bold);
     int pPolDl = Convert.ToInt32(g.MeasureString(aTekstGora,f1).Width / 2);
     int pPolDl2 = Convert.ToInt32(g.MeasureString(aTekstDol,f1).Width / 2);
     g.DrawString(aTekstGora,
         f1, Brushes.Black,new Point(aRozmiar.X + (SZEROKOSC_SLUPKA / 2) - pPolDl,aRozmiar.Y - 12));
     g.DrawString(aTekstDol,
         f1, Brushes.Black,new Point(aRozmiar.X + (SZEROKOSC_SLUPKA / 2) - pPolDl2,aRozmiar.Y + aRozmiar.Height + 4));
 }
Пример #22
0
        /// <summary>
        /// 取得文字的大小及繪製位置
        /// </summary>
        /// <param string="C_Str">文字字串</param>
        public void GetTextInfo(string C_Str)
        {
            SizeF TitSize = g.MeasureString(C_Str, Str_Font);                    //將繪製的字串進行格式化

            Str_Width     = TitSize.Width;                                       //取得字串的寬度
            Str_Height    = TitSize.Height;                                      //取得字串的高度
            Str_Odd_Width = Str_Width / (float)C_Str.Length;                     //取得單個文字的寬度
            Str_Width     = (float)((Str_Odd_Width + Str_block) * C_Str.Length); //取得文字的寬度
            Str_Width     = (Panel_W - Str_Width) / 2F;                          //使文字居中
            Str_Height    = Panel_H - Str_Height;                                //使文字顯示在控制元件底端
        }
Пример #23
0
		///<summary>Defines the bounds of the graphs to be drawn based on size of form.</summary>
		private void defineBounds(Graphics g) {
			minYH=border;
			maxYH=ClientSize.Height/2f-border;
			minYW=ClientSize.Height/2f+border;
			maxYW=ClientSize.Height-border;
			minX=border+g.MeasureString("230lbs",Font).Width;
			maxX=(ClientSize.Width)-border-g.MeasureString("230lbs",Font).Width;
			pixPerYear=(maxX-minX)/(float)(ageRange);
			pixPerInch=(maxYH-minYH)/(float)maxInches;
			pixPerPound=(maxYW-minYW)/(float)maxPounds;
		}
Пример #24
0
        public override System.Drawing.SizeF MeasureItem(System.Drawing.Graphics g, FontX font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant mtick, System.Drawing.PointF morg)
        {
            SplitInFirstPartAndExponent(mtick, out var firstpart, out var mant, out var middelpart, out var exponent);

            var   gdiFont = GdiFontManager.ToGdi(font);
            SizeF size1   = g.MeasureString(_prefix + firstpart + middelpart, gdiFont, new PointF(0, 0), strfmt);
            SizeF size2   = g.MeasureString(exponent, gdiFont, new PointF(size1.Width, 0), strfmt);
            SizeF size3   = g.MeasureString(_suffix, gdiFont, new PointF(0, 0), strfmt);

            return(new SizeF(size1.Width + size2.Width + size3.Width, size1.Height));
        }
Пример #25
0
 private void drawString(Graphics g, Control label, ComponentFactory.Krypton.Toolkit.KryptonTextBox textLabel)
 {
     Margins margins = printDocument.DefaultPageSettings.Margins;
     String text = label.Text;
     Font font = new Font(label.Font.FontFamily, label.Font.Size * x, label.Font.Style);
     RectangleF rect = new RectangleF(label.Location.X * x + margins.Left, label.Location.Y * y + margins.Top, g.MeasureString(text, font).Width * x, g.MeasureString(text, font).Height * y);
     g.DrawString(text, font, brush, rect, labelFormat);
     text = textLabel.Text;
     font = new Font(textLabel.StateCommon.Content.Font.FontFamily, textLabel.StateCommon.Content.Font.Size * x, textLabel.StateCommon.Content.Font.Style);
     rect = new RectangleF(textLabel.Location.X * x + margins.Left + textLabel.StateCommon.Content.Padding.All, textLabel.Location.Y * y + margins.Top, g.MeasureString(text, font).Width * x, g.MeasureString(text, font).Height * y);
     g.DrawString(text, font, brush, rect, textFormat);
 }
Пример #26
0
Файл: func.cs Проект: Fun33/code
    public float GetHeadFootWidth_eng(System.Drawing.Graphics g, System.Drawing.Font Fnt)
    {
        float ret = 0;

        string s1 = "a", s2 = "ab";
        float  t1 = g.MeasureString(s1, Fnt).Width;
        float  t2 = g.MeasureString(s2, Fnt).Width;

        ret = t2 - t1;

        return(ret);
    }
Пример #27
0
        public void SetDescription(string value)
        {
            SizeF size1, size2;

            using (System.Drawing.Graphics grfx = this.CreateGraphics())
            {
                size1 = grfx.MeasureString(value, _lblDescription.Font);
                size2 = grfx.MeasureString(value, _lblDescription.Font, _lblDescription.ClientSize.Width);
            }
            _lblDescription.Size      = new Size(_cbChoice.Size.Width, (int)(_lblDescription.PreferredHeight * Math.Ceiling(size2.Height / size1.Height)));
            this._lblDescription.Text = value;
        }
Пример #28
0
 private static bool IsFixedWidth(Graphics g, string font)
 {
     try
     {
         using (var f = new Font(font.Replace("(Default) ", String.Empty), 12))
             return g.MeasureString("M", f).Width == g.MeasureString(".", f).Width;
     }
     catch
     {
         return false;
     }
 }
Пример #29
0
Файл: func.cs Проект: Fun33/code
    public float GetHeadFootWidth_Digital(System.Drawing.Graphics eGraphics, System.Drawing.Font Fnt)
    {
        float ret = 0;

        string s1 = "1", s2 = "12";
        float  t1 = eGraphics.MeasureString(s1, Fnt).Width;
        float  t2 = eGraphics.MeasureString(s2, Fnt).Width;

        ret = t2 - t1;

        return(ret);
    }
Пример #30
0
 protected virtual void GetTextRects(out RectangleF titleRect, out RectangleF subtitleRect, Graphics graphics)
 {
     StringFormat format = new StringFormat(StringFormatFlags.FitBlackBox);
     format.Trimming = StringTrimming.EllipsisCharacter;
     format.Alignment = StringAlignment.Center;
     format.LineAlignment = StringAlignment.Center;
     format.Trimming = StringTrimming.None;
     SizeF sz = graphics.MeasureString(Title, titleFont, Width - bindingImage.Width, format);
     titleRect = new RectangleF(bindingImage.Width + subtitleFont.SizeInPoints, subtitleFont.SizeInPoints, sz.Width, sz.Height);
     SizeF sz1 = graphics.MeasureString(Subtitle, subtitleFont, Width - bindingImage.Width, format);
     subtitleRect = new RectangleF(bindingImage.Width + subtitleFont.SizeInPoints, titleRect.Height + subtitleFont.SizeInPoints, sz1.Width, sz1.Height);
 }
Пример #31
0
        public void Draw(System.Drawing.Graphics g)
        {
            Pen        dsoPen;
            SolidBrush dsoSolidBrush;

            switch (dsoType)
            {
            case "GALXY":
            case "GALCL":
                dsoPen        = galxyStrokePen;
                dsoSolidBrush = galxyFontColorBrush;
                break;

            case "PLNNB":
                dsoPen        = plNebulaStrokePen;
                dsoSolidBrush = plNebulaFontColorBrush;
                break;

            case "BRTNB":
            case "CL+NB":
                dsoPen        = nebulaStrokePen;
                dsoSolidBrush = nebulaFontColorBrush;
                break;

            case "GLOCL":
                dsoPen        = gloclStrokePen;
                dsoSolidBrush = gloclFontColorBrush;
                break;

            default:
                dsoPen        = dsoDefaultStrokePen;
                dsoSolidBrush = dsoDefaultFontColorBrush;
                break;
            }

            g.FillEllipse(dsoFillColorBrush, (float)(this.CenterPoint.X - this.RadiusWidth), (float)(this.CenterPoint.Y - this.RadiusHeight),
                          (float)(this.RadiusWidth * 2), (float)(this.RadiusHeight * 2));
            g.DrawEllipse(dsoPen, (float)(this.CenterPoint.X - this.RadiusWidth), (float)(this.CenterPoint.Y - this.RadiusHeight),
                          (float)(this.RadiusWidth * 2), (float)(this.RadiusHeight * 2));
            var size1 = g.MeasureString(this.Name1, dsoFont);

            g.DrawString(this.Name1, dsoFont, dsoSolidBrush, this.TextPosition.X - size1.Width / 2, (float)(this.TextPosition.Y));
            if (this.Name2 != null)
            {
                var size2 = g.MeasureString(this.Name2, dsoFont);
                g.DrawString(this.Name2, dsoFont, dsoSolidBrush, this.TextPosition.X - size2.Width / 2, (float)(this.TextPosition.Y + size1.Height + 2));
                if (this.Name3 != null)
                {
                    var size3 = g.MeasureString(this.Name3, dsoFont);
                    g.DrawString(this.Name3, dsoFont, dsoSolidBrush, this.TextPosition.X - size3.Width / 2, (float)(this.TextPosition.Y + size1.Height + 2 + size2.Height + 2));
                }
            }
        }
Пример #32
0
        public virtual void DrawString(RectangleF area, Graphics g, String text, FontFamily ff, Color c)
        {
            SizeF size = g.MeasureString(text, new Font(ff, 32));
            double difX = (size.Width - area.Width) / -size.Width;

            double difY = (size.Height - area.Height) / -size.Height;
            float finalFontSize = 32 + (float)(32 * Math.Min(difX, difY));
            SizeF finalSize = g.MeasureString(text, new Font(ff, finalFontSize));

            g.DrawString(text, new Font(ff, finalFontSize), new SolidBrush(c),
                new PointF((area.Width - finalSize.Width) / 2 + area.Left, (area.Height - finalSize.Height) / 2 + area.Height));
            g.Flush();
        }
Пример #33
0
        protected Size CalcClientSize()
        {
            System.Drawing.Size size = Size.Empty;

            using (System.Drawing.Graphics g = this.CreateGraphics())
            {
                if (this.Icon != null)
                {
                    size = this.Icon.Size;
                }

                if (this.ShowCloseButton)
                {
                    if (size.Width != 0)
                    {
                        size.Width += TIPMARGIN;
                    }

                    size.Width += (CLOSEBUTTON_WIDTH + TIPMARGIN);
                    size.Height = Math.Max(size.Height, CLOSEBUTTON_HEIGHT);
                }

                if (this.Caption.Length != 0)
                {
                    if (size.Width != 0)
                    {
                        size.Width += TIPMARGIN;
                    }

                    System.Drawing.Size captionSize = Size.Ceiling(g.MeasureString(Caption, this.CaptionFont));
                    size.Width += captionSize.Width;
                    size.Height = Math.Max(captionSize.Height, size.Height);
                }

                headerSize = size;

                string text = this.Content;

                if ((text != null) && (text.Length != 0))
                {
                    size.Height += TIPMARGIN;

                    System.Drawing.Size textSize = Size.Ceiling(g.MeasureString(text, this.Font));
                    size.Height     += textSize.Height;
                    size.Width       = Math.Max(textSize.Width, headerSize.Width);
                    headerSize.Width = size.Width;
                }
            }

            return(size);
        }
Пример #34
0
        private void getTitlePage()
        {
            try
            {
                JsonReader        reader     = new JsonTextReader(new StringReader(WebRequestHelper.getData("http://mbbsweb.azurewebsites.net/api/Module/GetModuleInfo?moduleID=" + data.ModuleName, data.Token)));
                string            text       = WebRequestHelper.getData("http://mbbsweb.azurewebsites.net/api/Module/GetModuleInfo?moduleID=" + data.ModuleName, data.Token);
                ModuleInformation moduleInfo = JsonConvert.DeserializeObject <ModuleInformation>(text);
                XFont             titleFont  = new XFont("Verdana", 15, XFontStyle.Bold);

                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1)))
                {
                    SizeF  size      = graphics.MeasureString(moduleInfo.ModuleName, new Font("Verdana", 15, FontStyle.Bold, GraphicsUnit.Point));
                    Double textWidth = (double)size.Width / 2;
                    XRect  titleRect = new XRect((pdfPage.Width / 2) - textWidth / 1.4, 100, someWidth, 200);
                    tf.DrawString(moduleInfo.ModuleName, titleFont, XBrushes.Black, titleRect, XStringFormats.TopLeft);
                    size      = graphics.MeasureString(data.ModuleName, new Font("Verdana", 15, FontStyle.Bold, GraphicsUnit.Point));
                    textWidth = (double)size.Width / 2;
                    titleRect = new XRect(pdfPage.Width / 2 - textWidth / 1.4, 120, someWidth, 200);
                    tf.DrawString(data.ModuleName, titleFont, XBrushes.Black, titleRect, XStringFormats.TopLeft);
                }



                XFont infoText = new XFont("Verdana", 10, XFontStyle.Regular);
                XRect infoRect = new XRect(myX, pdfPage.Height - 200, someWidth, 200);
                tf.DrawString(moduleInfo.LocationName, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 190, someWidth, 200);
                tf.DrawString(moduleInfo.Sector, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 180, someWidth, 200);
                tf.DrawString(moduleInfo.POBox, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 170, someWidth, 200);
                tf.DrawString(moduleInfo.PostalCode, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 160, someWidth, 200);
                tf.DrawString(moduleInfo.Phone, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 150, someWidth, 200);
                tf.DrawString(moduleInfo.Website, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                pdfPage = pdf.AddPage();
                graph   = XGraphics.FromPdfPage(pdfPage);
                tf      = new XTextFormatter(graph);
            }
            catch
            {
                getTitlePage();
            }
        }
Пример #35
0
        /// <summary>
        /// Draw tooltip information on a tooltip window.
        /// </summary>
        /// <param name="title">Tooltip title.</param>
        /// <param name="text">Tooltip text.</param>
        /// <param name="img">Tooltip image.</param>
        /// <param name="g">Graphics object used to paint.</param>
        /// <param name="rect">Bounding rectangle where tooltip information to be drawn.</param>
        public static void drawToolTip(string title, string text, Image img, System.Drawing.Graphics g, Rectangle rect)
        {
            SizeF tSize = new SizeF();
            int   y     = 0;

            switch (getContent(title, text, img))
            {
            case Content.All:
                g.DrawString(title, TitleFont, TextBrush, rect.X + 4, rect.Y + 4);
                tSize = g.MeasureString(title, TitleFont);
                y     = (int)(8 + tSize.Height);
                g.DrawLine(SeparatorPen, rect.X + 4, y, rect.Right - 4, y);
                g.DrawLine(new Pen(Color.FromArgb(255, 255, 255)), rect.X + 4, y + 1, rect.Right - 4, y + 1);
                y = y + 4;
                g.DrawImage(img, rect.X + 4, y, img.Width, img.Height);
                g.DrawString(text, TextFont, TextBrush, rect.X + img.Width + 8, y);
                break;

            case Content.TitleAndImage:
                g.DrawImage(img, rect.X + 4, rect.Y + 4, img.Width, img.Height);
                g.DrawString(title, TitleFont, TextBrush, rect.X + 8 + img.Width, rect.Y + 4);
                break;

            case Content.TitleAndText:
                g.DrawString(title, TitleFont, TextBrush, rect.X + 4, rect.Y + 4);
                tSize = g.MeasureString(title, TitleFont);
                y     = (int)(8 + tSize.Height);
                g.DrawLine(SeparatorPen, rect.X + 4, y, rect.Right - 4, y);
                g.DrawLine(new Pen(Color.FromArgb(255, 255, 255)), rect.X + 4, y + 1, rect.Right - 4, y + 1);
                y = y + 4;
                g.DrawString(text, TextFont, TextBrush, rect.X + 4, y);
                break;

            case Content.TitleOnly:
                g.DrawString(title, TitleFont, TextBrush, rect.X + 4, rect.Y + 4);
                break;

            case Content.ImageAndText:
                g.DrawImage(img, rect.X + 4, rect.Y + 4, img.Width, img.Height);
                g.DrawString(text, TextFont, TextBrush, rect.X + 8 + img.Width, rect.Y + 4);
                break;

            case Content.ImageOnly:
                g.DrawImage(img, rect.X + 4, rect.Y + 4, img.Width, img.Height);
                break;

            case Content.TextOnly:
                g.DrawString(text, TextFont, TextBrush, rect.X + 4, rect.Y + 4);
                break;
            }
        }
Пример #36
0
        private string AdjustPathString(Graphics grx, string text)
        {
            SizeF size = grx.MeasureString(text, this.Font);
            while (this.Size.Width < size.Width)
            {
                string text2 = ShortenPathString(text);
                if (text == text2)
                    break;
                size = grx.MeasureString(text2, this.Font);
                text = text2;
            }

            return text;
        }
Пример #37
0
        private bool InitializeChar(System.Drawing.Graphics graphics, int bitmapWidth, int bitmapHeight, System.Drawing.Font font, int fontSize, float xWidth, float xHeight, char c, FontStyle style, ref float currentX, ref float currentY)
        {
            var    charKey = new CharKey(c, style);
            string s       = new string(c, 1);

            if (char.IsWhiteSpace(c))
            {
                _charEntries[charKey] = new CharEntry {
                    TextureWidth = graphics.MeasureString("X" + s + "X", font).Width - graphics.MeasureString("xx", font).Width
                };
                return(true);
            }

            RectangleF charRectangle = MeasureRectangle(graphics, fontSize, font, s);
            float      charWidth = charRectangle.Width, charHeight = charRectangle.Height;

            if (currentX + charWidth + xWidth > bitmapWidth)
            {
                currentX  = 0;
                currentY += xHeight;

                if (currentY + xHeight > bitmapHeight)
                {
                    // We have run out of space in our image for further characters. This means we need a larger image texture --
                    // though on the other hand, we can't properly handle most Unicode characters anyway, so the whole approach
                    // might need rethinking.
                    return(false);
                }
            }

            graphics.DrawString(s, font, Brushes.White, currentX + 0.5f * xWidth - charRectangle.Left, currentY);

            float measuredCharWidth = graphics.MeasureString("X" + s + "X", font).Width - graphics.MeasureString("XX", font).Width;

            _charEntries[charKey] = new CharEntry
            {
                TextureX      = currentX / bitmapWidth,
                TextureY      = currentY / bitmapHeight,
                TextureWidth  = (charWidth + xWidth) / bitmapWidth,
                TextureHeight = charHeight / bitmapHeight,

                BoxLeft    = 0.5f * xWidth / xHeight,
                BoxRight   = (charWidth + 0.5f * xWidth) / xHeight,
                InnerWidth = measuredCharWidth / xHeight,
            };

            currentX += charWidth + xWidth;
            return(true);
        }
Пример #38
0
        private Image CreateAtlasImage(Atlas _Atlas, List <string> _Sources)
        {
            Image img = new Bitmap(_Atlas.Width, _Atlas.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img);

            if (DebugMode)
            {
                g.FillRectangle(Brushes.Green, new Rectangle(0, 0, _Atlas.Width, _Atlas.Height));
            }

            for (var index = 0; index < _Atlas.Nodes.Count; index++)
            {
                Node   node   = _Atlas.Nodes[index];
                string source = _Sources?[index];

                if (node.Texture != null)
                {
                    Image sourceImg = Image.FromFile(source ?? node.Texture.Source);
                    g.DrawImage(sourceImg, node.Bounds);

                    if (DebugMode)
                    {
                        string     label      = Path.GetFileNameWithoutExtension(node.Texture.Source);
                        SizeF      labelBox   = g.MeasureString(label, SystemFonts.MenuFont, new SizeF(node.Bounds.Size));
                        RectangleF rectBounds = new Rectangle(node.Bounds.Location,
                                                              new Size((int)labelBox.Width, (int)labelBox.Height));
                        g.FillRectangle(Brushes.Black, rectBounds);
                        g.DrawString(label, SystemFonts.MenuFont, Brushes.White, rectBounds);
                    }
                }
                else
                {
                    g.FillRectangle(Brushes.DarkMagenta, node.Bounds);

                    if (DebugMode)
                    {
                        string     label      = node.Bounds.Width + "x" + node.Bounds.Height;
                        SizeF      labelBox   = g.MeasureString(label, SystemFonts.MenuFont, new SizeF(node.Bounds.Size));
                        RectangleF rectBounds = new Rectangle(node.Bounds.Location,
                                                              new Size((int)labelBox.Width, (int)labelBox.Height));
                        g.FillRectangle(Brushes.Black, rectBounds);
                        g.DrawString(label, SystemFonts.MenuFont, Brushes.White, rectBounds);
                    }
                }
            }

            return(img);
        }
Пример #39
0
 private void GUITimer_Tick(object sender, EventArgs e)
 {
     var Rects = new Rectangle(Left, Top, Left + Width, Top + Height);
     if ((Top < 0 && Win32.PtInRect(ref Rects, Cursor.Position)))
     {
         Top = 0;
     }
     else
     {
         if (Top > -5 && Top < 5 && !(Win32.PtInRect(ref Rects, Cursor.Position)))
         {
             Top = 2 - Height;
         }
     }
     g = Mini_Artist_Label.CreateGraphics();
     if (g.MeasureString(Artist, Mini_Artist_Label.Font).Width > Mini_Artist_Label.Width)
     {
         Mini_Artist_Label.Refresh();
         s = g.MeasureString(Artist, Mini_Artist_Label.Font);//测量文字长度
         if (tempA != Artist)//文字改变时,重新显示
         {
             pA = new PointF(Mini_Artist_Label.Size.Width, 0);
             tempA = Artist;
         }
         else
             pA = new PointF(pA.X - 10, 0);//每次偏移10
         if (pA.X <= -s.Width)
             pA = new PointF(Mini_Artist_Label.Size.Width, 0);
         g.DrawString(Artist, Mini_Artist_Label.Font, brush, pA);
     }
     else { Mini_Artist_Label.Text = Artist; }
     g = Mini_Title_Label.CreateGraphics();
     if (g.MeasureString(Title, Mini_Title_Label.Font).Width > Mini_Title_Label.Width)
     {
         Mini_Title_Label.Refresh();
         s = g.MeasureString(Title, Mini_Title_Label.Font);//测量文字长度
         if (tempB != Title)//文字改变时,重新显示
         {
             pB = new PointF(Mini_Title_Label.Size.Width, 0);
             tempB = Title;
         }
         else
             pB = new PointF(pB.X - 10, 0);//每次偏移10
         if (pB.X <= -s.Width)
             pB = new PointF(Mini_Title_Label.Size.Width, 0);
         g.DrawString(Title, Mini_Title_Label.Font, brush, pB);
     }
     else { Mini_Title_Label.Text = Title; }
 }
Пример #40
0
        /// <summary>
        /// 在两个X坐标区域中.画"字符"
        /// </summary>
        /// <param name="col1">x1</param>
        /// <param name="col2">x2</param>
        /// <param name="strPrint">字符</param>
        /// <param name="LocationY">y</param>
        /// <param name="e"></param>
        private void m_mthDrawStrAtRectangle(float col1, float col2, string strPrint, float

                                             LocationY, System.Drawing.Printing.PrintPageEventArgs e)
        {
            System.Drawing.Graphics g       = e.Graphics;
            System.Drawing.Font     objfont = new System.Drawing.Font("宋体", 10);
            SizeF s = g.MeasureString(strPrint, objfont);

            if (s.Width >= col2 - col1)
            {
                objfont = new System.Drawing.Font("宋体", 8);
                s       = g.MeasureString(strPrint, objfont);
            }
            float ji = col2 - col1;
            //float X =  col1 + ji/2 - s.Width/2;
            float X = col1 + 3;
            //			float Y = LocationY + this.m_fltZijiHeight;
            float Y = LocationY + m_ftlRowHeight / 2 - s.Height / 2;

            if (s.Width > ji)
            {
                objfont = new System.Drawing.Font("宋体", 8);
                float  flt          = ji / g.MeasureString("测", objfont).Width;
                int    intcharCount = Convert.ToInt32(flt) + 1;
                float  y1           = LocationY + m_ftlRowHeight / 4 - s.Height / 2 + 2;
                float  y2           = LocationY + 3 * m_ftlRowHeight / 4 - s.Height / 2;
                string strPrint1    = strPrint.Substring(0, intcharCount);
                //float x1 =  col1 + ji/2 - g.MeasureString(strPrint1,objfont).Width/2;
                float x1 = col1 + 3;
                g.DrawString(strPrint1, objfont, this.m_objBrush, x1, y1);

                string strPrint2 = "";
                if (strPrint.Length - intcharCount <= intcharCount)
                {
                    strPrint2 = strPrint.Substring(intcharCount);
                }
                else
                {
                    strPrint2 = strPrint.Substring(intcharCount, intcharCount);
                }
                //	x1 =  col1 + ji/2 - g.MeasureString(strPrint2,objfont).Width/2;
                x1 = col1 + 3;
                g.DrawString(strPrint2, objfont, this.m_objBrush, x1, y2);
            }
            else
            {
                g.DrawString(strPrint, objfont, this.m_objBrush, X, Y);
            }
        }
        /// <summary>
        /// Fits the string to an area.
        /// </summary>
        /// <param name="g">The g.</param>
        /// <param name="Text">The Text.</param>
        /// <param name="font">The font.</param>
        /// <param name="maxLength">max length in pixel which is available</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev08, 2008-12-09</remarks>
        private static string FitStringToArea(Graphics g, string text, Font font, int maxLength)
        {
            SizeF area = g.MeasureString(text, font);
            for (int i = 0; ((int)area.Width > maxLength); i++)
            {
                text = text.Substring(0, text.Length - 2);
                area = g.MeasureString(text, font);

                //important do avoid a endless loop
                if (i >= FIT_STRING_TO_AREA_TIMEOUT)
                    return text;
            }

            return text;
        }
Пример #42
0
        public void InitializeDescription(string value)
        {
            SizeF size1, size2;

            using (System.Drawing.Graphics grfx = this.CreateGraphics())
            {
                size1 = grfx.MeasureString(value, m_Label1.Font);
                size2 = grfx.MeasureString(value, m_Label1.Font, m_Label1.ClientSize.Width);
            }
            m_Label1.Size      = new Size(_cbChoice.Size.Width, (int)(m_Label1.PreferredHeight * Math.Ceiling(size2.Height / size1.Height)));
            this.m_Label1.Text = value;

            this._cbChoice.Location = new Point(m_Label1.Location.X, m_Label1.Bounds.Bottom + _cbChoice.Size.Height / 2);
            this.ClientSize         = new Size(this.ClientSize.Width, _cbChoice.Bounds.Bottom);
        }
        public void DrawText(string text, FontLabel font, Position position)
        {
            if (!Validate(font.Brush))
            {
                return;
            }

            using var gdiFont = font.ToGdi();
            var gdiSize = _graph.MeasureString(text, gdiFont);

            using var gdiBrush  = font.Brush.ToGdi(new Rectangle(position, gdiSize.ToVisualizer()));
            using var gdiFormat = font.TextFormat.ToGdi();

            _graph.DrawString(text, gdiFont, gdiBrush, position.ToGdi(), gdiFormat);
        }
Пример #44
0
        protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            if (value == null)
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
                return;
            }

            PossibleMatch match = (PossibleMatch)value;

            // draw the native combo first, we are just painting on top of it, not redrawing from scratch
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, match.Movie.Title, errorText, cellStyle, advancedBorderStyle, paintParts);

            string yearText     = "(" + match.Movie.Year + ")";
            string altTitleText = "as " + match.Result.AlternateTitle;
            string providerName = match.Movie.PrimarySource == null ? string.Empty : match.Movie.PrimarySource.Provider.Name;

            // figure basic positioning
            SizeF providerSize = graphics.MeasureString(providerName, DataGridView.Font);
            SizeF titleSize    = graphics.MeasureString(match.Movie.Title, DataGridView.Font);
            SizeF yearSize     = graphics.MeasureString(yearText, DataGridView.Font);

            int providerPosition = (int)(cellBounds.X + cellBounds.Width - providerSize.Width - 25);
            int yearPosition     = (int)(cellBounds.X + titleSize.Width);
            int altTitlePosition = (int)(cellBounds.X + titleSize.Width + yearSize.Width);

            // draw year
            RectangleF yearRect = new RectangleF(cellBounds.X + titleSize.Width, cellBounds.Y + 4, cellBounds.Width - providerSize.Width - 25, cellBounds.Height);

            graphics.DrawString(yearText, DataGridView.Font, SystemBrushes.ControlDark, yearRect);

            // draw alternate title if needed
            if (match.Result.AlternateTitleUsed())
            {
                graphics.DrawString(altTitleText, DataGridView.Font, SystemBrushes.ControlDark, altTitlePosition, cellBounds.Y + 4);
            }

            // draw data provider if needed
            if (!string.IsNullOrEmpty(providerName))
            {
                bool uncertainMatch = match.Result.TitleScore > 0 || match.Result.YearScore > 0;
                if (MovingPicturesCore.Settings.AlwaysDisplayProviderTags || !match.Result.FromTopSource || (uncertainMatch && match.HasMultipleSources))
                {
                    graphics.FillRectangle(SystemBrushes.ControlLight, providerPosition + 1, cellBounds.Y + 4, providerSize.Width + 1, cellBounds.Height - 10);
                    graphics.DrawString(providerName, DataGridView.Font, SystemBrushes.ControlDark, providerPosition + 1, cellBounds.Y + 4);
                }
            }
        }
Пример #45
0
            public void DrawPointer(System.Drawing.Graphics Graphics)
            {
                Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                GraphicsPath path = new GraphicsPath();
                int          a    = 0;

                if (this.LinearGauge.MinimumValue < 0)
                {
                    a = (int)Math.Ceiling((((Math.Abs(this.LinearGauge.MinimumValue) + LinearGauge.Value) / (float)LinearGauge.MajorDifference) * m_minorTicksPixels));
                }
                else
                {
                    a = (int)Math.Ceiling(((LinearGauge.Value / (float)LinearGauge.MajorDifference) * m_minorTicksPixels));
                }
                int y = (this.LinearGauge.Height / 2 + 5 + LinearGauge.MajorTicksHeight) - LinearGauge.MajorTicksHeight;

                a = 10 + (int)Math.Ceiling((majorTicksDistance * m_minorTicksPixels)) - a;
                Rectangle rect  = new Rectangle(new Point(this.LinearGauge.Width / 2 + 28, a), new Size(32, 32));
                SizeF     sf    = Graphics.MeasureString(this.LinearGauge.Value.ToString(), this.LinearGauge.GaugelabelFont);
                PointF    point = new PointF(rect.X + rect.Width / 2 - sf.Width / 2, rect.Y + rect.Height / 2 - sf.Height / 2);

                Graphics.FillEllipse(new SolidBrush(LinearGauge.NeedleColor), rect);
                Graphics.DrawEllipse(new Pen(ColorTranslator.FromHtml("#00a0d1")), rect);
                Graphics.DrawLine(new Pen(ColorTranslator.FromHtml("#00a0d1")), rect.X, rect.Y + rect.Height / 2, rect.X - 18, rect.Y + rect.Height / 2);
                Graphics.DrawString(Math.Round(LinearGauge.Value, 2).ToString(), this.LinearGauge.GaugelabelFont, new SolidBrush(ColorTranslator.FromHtml("#ffffff")), point);
            }
Пример #46
0
        public void RenderSysString(String msg, bool invert, Rectangle rect)
        {
            if (rect.Width == 0 && rect.Height == 0)
            {
                rect.Width  = width;
                rect.Height = height;
            }

            if (sys_font == null)
            {
                sys_font = new System.Drawing.Font(font_names[cur_font], font_pt, System.Drawing.FontStyle.Bold);
            }
            SizeF str_bounds = graph.MeasureString(msg, sys_font, new Point(0, 0), System.Drawing.StringFormat.GenericDefault);
            Brush br         = invert ? inverted_txt_brush : default_txt_brush;

            int x = (int)((rect.Width / 2) - (str_bounds.Width / 2) + rect.X);
            int y = (int)((rect.Height / 2) - (str_bounds.Height / 2) + rect.Y);

            if (invert)
            {
                Rectangle invert_rect = new Rectangle(x, y, (int)(str_bounds.Width + 4), (int)(str_bounds.Height + 4));
                graph.FillRectangle(inverted_clear_brush, invert_rect);
            }

            graph.DrawString(msg, sys_font, invert ? inverted_txt_brush : default_txt_brush, x, y);
        }
Пример #47
0
        /// <summary>Adds a textual string to a bitmap image</summary>
        /// <param name="bitmap">The bitmap image to add the text to, or a null reference if a new image is to be created</param>
        /// <param name="txt">The text to overlay</param>
        /// <param name="fontname">The name of the font to use</param>
        /// <param name="fontsize">The size in points of the font</param>
        /// <param name="bgcolor">The background color to use (Only relevant if creating a new image)</param>
        /// <param name="fcolor">The font color to use</param>
        /// <param name="Padding">The padding to use, or alternatively the X,Y inset if overlaying text</param>
        public static Bitmap AddTextToBitmap(Bitmap bitmap, string txt, string fontname, int fontsize, Color bgcolor, Color fcolor, Vector2 Padding)
        {
            bool  overlay = true;
            SizeF size;

            if (bitmap == null)
            {
                bitmap  = new Bitmap(1024, 1024);
                overlay = false;
            }

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
            {
                Font font = new Font(fontname, fontsize);
                size = graphics.MeasureString(txt, font);
                if (!overlay)
                {
                    graphics.FillRectangle(new SolidBrush(bgcolor), 0, 0, size.Width + (int)Padding.X * 2, size.Height + (int)Padding.Y * 2);
                }

                graphics.DrawString(txt, font, new SolidBrush(fcolor), (int)Padding.X, (int)Padding.Y);
                graphics.Flush();
                font.Dispose();
            }

            if (!overlay)
            {
                Rectangle cropArea = new Rectangle(0, 0, (int)size.Width + (int)Padding.X * 2, (int)size.Height + (int)Padding.Y * 2);
                return(bitmap.Clone(cropArea, bitmap.PixelFormat));
            }

            return(bitmap);
        }
Пример #48
0
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            //base.Paint(g, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            Brush textColor = CellFunctions.DrawPlainBackground(this, this.Enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);

            //float y = (cellBounds.Height - textSize.Height) / 2 + cellBounds.Y;
            SizeF textSize = g.MeasureString(this.Value as String, _parent.Font);

            if ((textSize.Width + 13) > cellBounds.Width)
            {
                g.DrawString(this.Value as String, _parent.Font, textColor, new RectangleF(new PointF(cellBounds.X + 3.0f, cellBounds.Y), new SizeF(cellBounds.Width - 13, cellBounds.Height)));
            }
            else
            {
                float y = CellFunctions.TextCenterYInRact(cellBounds, g, _parent.Font);
                g.DrawString(this.Value as String, _parent.Font, textColor, new PointF(cellBounds.X + 3.0f, y));
            }
            float margin     = (cellBounds.Height - 10) / 2;
            float pathTop    = cellBounds.Y + margin; //path의 height를 10으로 한다.
            float PathBottom = cellBounds.Y + cellBounds.Height - margin;

            g.FillPath(Brushes.Gainsboro, new GraphicsPath(
                           new PointF[] {
                new PointF(cellBounds.Right - 10, pathTop),
                new PointF(cellBounds.Right - 10, PathBottom),
                new PointF(cellBounds.Right - 3, (pathTop + PathBottom) / 2)
            },
                           new byte[] {
                (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line
            }, FillMode.Winding));
        }
        public override void OnDraw(System.Drawing.Graphics g)
        {
            SizeF sz = DrawSize;

            System.Drawing.Font font = this.TextFont;
            string s    = this.VariableName;
            SizeF  size = g.MeasureString(s, font);

            if (IsFocused)
            {
                g.FillRectangle(this.TextBrushBKFocus, 0, 0, sz.Width, sz.Height);
                g.DrawString(s, this.TextFont, this.TextBrushFocus, new PointF(0, 0));
                if (!string.IsNullOrEmpty(_subscript))
                {
                    g.DrawString(_subscript, _subscriptFont, this.TextBrushFocus, new PointF(size.Width, size.Height / (float)2));
                }
            }
            else
            {
                g.DrawString(s, font, this.TextBrush, new PointF(0, 0));
                if (!string.IsNullOrEmpty(_subscript))
                {
                    g.DrawString(_subscript, _subscriptFont, this.TextBrush, new PointF(size.Width, size.Height / (float)2));
                }
            }
        }
Пример #50
0
Файл: func.cs Проект: Fun33/code
    //取字的高度
    private float GetHeighString(string Str, System.Drawing.Graphics eGraphics, System.Drawing.Font Fnt)
    {
        //System.Drawing.Font Fnt = G1.DefaultCellStyle.Font;
        float fontwidth = eGraphics.MeasureString(Str, Fnt).Height;

        return(fontwidth);
    }
Пример #51
0
Файл: func.cs Проект: Fun33/code
    //sample
    //MessageBox.Show(new func().GetMeasureString("12345678901234",this.CreateGraphics(), this.Font).ToString());
    //   MessageBox.Show(new func().GetMeasureString("一二三四五六七八九十", this.CreateGraphics(), this.Font).ToString());
    //   MessageBox.Show(new func().GetMeasureString("一二三四五", this.CreateGraphics(), this.Font).ToString());
    //取字的寬度
    public float GetMeasureString(string Str, System.Drawing.Graphics eGraphics, System.Drawing.Font Fnt)
    {
        //System.Drawing.Font Fnt = G1.DefaultCellStyle.Font;
        float fontwidth = eGraphics.MeasureString(Str, Fnt).Width;

        return(fontwidth);
    }
Пример #52
0
Файл: func.cs Проект: Fun33/code
    public float GetSpaceWidth(System.Drawing.Graphics eGraphics, System.Drawing.Font Fnt)
    {
        float ret = 0;

        string s1 = "", s2 = "";

        s1 = "我 你";
        float t1 = eGraphics.MeasureString(s1, Fnt).Width;

        s2 = "我你";
        float t2 = eGraphics.MeasureString(s2, Fnt).Width;

        ret = t1 - t2;

        return(ret);
    }
Пример #53
0
        private static Font GetFontForStringAndRegion(string value, TemplateRegion region, Graphics g)
        {
            int fontPoint = 20;

            while (true)
            {
                FontStyle fontStyle = FontStyle.Regular;

                if (region.Bold)
                {
                    fontStyle = FontStyle.Bold | fontStyle;
                }
                if (region.Italic)
                {
                    fontStyle = FontStyle.Italic | fontStyle;
                }
                Font testFont = new Font("Arial", 14, fontStyle);

                SizeF size = g.MeasureString(value, testFont, region.Region.Width);

                if (size.Height > region.Region.Height)
                {
                    fontPoint -= 2;

                    if (fontPoint == 0)
                    {
                        return testFont;
                    }
                }
                else
                {
                    return testFont;
                }
            }
        }
Пример #54
0
            public override void m_mthPrintNextLine(ref int p_intPosY, System.Drawing.Graphics p_objGrp, System.Drawing.Font p_fntNormalText)
            {
                if (m_objContent == null || m_objContent.m_objItemContents == null)
                {
                    m_blnHaveMoreLine = false;
                    return;
                }
                if (!(m_blnHavePrintInfo(m_strKeysArr1) == true || m_blnHavePrintInfo(m_strKeysArr2) == true ||
                      m_blnHavePrintInfo(m_strKeysArr3) == true || m_blnHavePrintInfo(m_strKeysArr4) == true || m_blnHavePrintInfo(m_strKeysArr5) == true ||
                      m_blnHavePrintInfo(m_strKeysArr6) == true))
                {
                    m_blnHaveMoreLine = false;
                    return;
                }
                if (m_blnIsFirstPrint)
                {
                    SizeF size      = p_objGrp.MeasureString("Apgar评分表", m_fontItemMidHead);
                    int   intMiddle = (clsPrintPosition.c_intRightX - clsPrintPosition.c_intLeftX) / 2 - Convert.ToInt32(size.Width / 2);
                    p_intPosY += 20;
                    p_objGrp.DrawString("Apgar评分表", m_fontItemMidHead, Brushes.Black, intMiddle, p_intPosY);
                    p_intPosY += 20;
                    string strAllText = "";
                    string strXml     = "";
                    if (m_objContent != null)
                    {
//						if(m_blnHavePrintInfo(m_strKeysArr) != false)
//							m_mthMakeText(new string[]{"肌营养:","肌张力:"},m_strKeysArr,ref strAllText,ref strXml);
////						m_mthMakeCheckText(m_strKeysArr1,ref strAllText,ref strXml);
//						if(m_blnHavePrintInfo(m_strKeysArr) != false)
//							m_mthMakeText(new string[]{"不自主运动:","肌力:"},m_strKeysArr2,ref strAllText,ref strXml);
                    }
                    else
                    {
                        m_blnHaveMoreLine = false;
                        return;
                    }
                    m_objPrintContext.m_mthSetContextWithCorrectBefore(strAllText, strXml, m_dtmFirstPrintTime, m_objContent.m_objItemContents != null);
                    m_mthAddSign2("Apgar评分表", m_objPrintContext.m_ObjModifyUserArr);

                    m_blnIsFirstPrint = false;
                }

                if (m_objPrintContext.m_BlnHaveNextLine())
                {
                    m_objPrintContext.m_mthPrintLine((int)enmRectangleInfoInPatientCaseInfo.PrintWidth, m_intRecBaseX + 50, p_intPosY, p_objGrp);
                    p_intPosY += 20;
                    m_intTimes++;
                }

                if (m_objPrintContext.m_BlnHaveNextLine())
                {
                    m_blnHaveMoreLine = true;
                }
                else
                {
                    p_intPosY += 10;
                    m_mthPrintSportTable(ref p_intPosY, p_objGrp, p_fntNormalText);
                    m_blnHaveMoreLine = false;
                }
            }
Пример #55
0
        public void UpdateTab(int index, string title, Color backgroundColor, Color textColor)
        {
            if (index < 0 || index >= this.tabs.Count)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            var tab = this.tabs[index];

            tab.Title           = title;
            tab.BackgroundColor = backgroundColor;
            tab.ForegroundColor = textColor;

            int width = tab.Width;

            using (var sf = new StringFormat(StringFormat.GenericTypographic))
            {
                width = (int)Math.Round(g.MeasureString(title, this.Font, 999999, sf).Width + 11);
            }

            int diff = (width - tab.Width);

            tab.Width = width;

            for (int i = index + 1; i < this.tabs.Count; i++)
            {
                this.tabs[i].Left += diff;
            }

            this.maxWidth += diff;

            Invalidate();
        }
Пример #56
0
		private void DrawContent(Graphics graphics, Rectangle rect)
		{
			using (LinearGradientBrush brush = new LinearGradientBrush(new Point(0, 0),
				new Point(rect.Width, rect.Height), Color.White, Color.LightGreen))
			{
				graphics.FillRectangle(brush, rect);
			}

			if (!string.IsNullOrEmpty(_title))
			{
				using (Font titleFont = new Font(FontFamily.GenericSansSerif, 18.0f, FontStyle.Bold))
				{
					graphics.DrawString(_title, titleFont, Brushes.Black, rect);

					// Update the rect to position the body text
					SizeF titleSize = graphics.MeasureString(_title, titleFont, rect.Width);
					int titleHeight = (int)titleSize.Height + 1;
					rect.Offset(0, titleHeight);
					rect.Height -= titleHeight;
				}
			}

			if (!string.IsNullOrEmpty(_description))
			{
				using (Font bodyFont = new Font(FontFamily.GenericSerif, 12.0f, FontStyle.Regular))
				{
					rect.Inflate(-2, 0);
					graphics.DrawString(_description, bodyFont, Brushes.Black, rect);
				}
			}
		}
        public override SizeF OnCalculateDrawSize(System.Drawing.Graphics g)
        {
            string s = this.ToString();

            System.Drawing.Font font = this.TextFont;
            return(g.MeasureString(s, font));
        }
Пример #58
0
 /// <summary>
 /// 功能描述:根据控件宽度截取字符串
 /// 作  者:HZH
 /// 创建日期:2019-06-27 10:49:10
 /// 任务编号:POS
 /// </summary>
 /// <param name="strSource">字符串</param>
 /// <param name="fltControlWidth">控件宽度</param>
 /// <param name="g">Graphics</param>
 /// <param name="font">字体</param>
 /// <returns>截取后的字符串</returns>
 public static string GetSubString(
     string strSource,
     float fltControlWidth,
     System.Drawing.Graphics g,
     System.Drawing.Font font)
 {
     try
     {
         fltControlWidth = fltControlWidth - 20;
         strSource       = strSource.Trim();
         while (true)
         {
             System.Drawing.SizeF sizeF = g.MeasureString(strSource.Replace(" ", "A"), font);
             if (sizeF.Width > fltControlWidth)
             {
                 strSource = strSource.TrimEnd('…');
                 if (strSource.Length <= 1)
                 {
                     return("");
                 }
                 strSource = strSource.Substring(0, strSource.Length - 1).Trim() + "…";
             }
             else
             {
                 return(strSource);
             }
         }
     }
     finally
     {
         g.Dispose();
     }
 }
Пример #59
0
        public override void Draw(Graphics g)
        {
            System.Drawing.Size st = g.MeasureString(Marker.ToolTipText, Font).ToSize();
             System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y - st.Height, st.Width + TextPadding.Width, st.Height + TextPadding.Height);
             rect.Offset(Offset.X, Offset.Y);

             using(GraphicsPath objGP = new GraphicsPath())
             {
            objGP.AddLine(rect.X + 2 * Radius, rect.Y + rect.Height, rect.X + Radius, rect.Y + rect.Height + Radius);
            objGP.AddLine(rect.X + Radius, rect.Y + rect.Height + Radius, rect.X + Radius, rect.Y + rect.Height);

            objGP.AddArc(rect.X, rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 90, 90);
            objGP.AddLine(rect.X, rect.Y + rect.Height - (Radius * 2), rect.X, rect.Y + Radius);
            objGP.AddArc(rect.X, rect.Y, Radius * 2, Radius * 2, 180, 90);
            objGP.AddLine(rect.X + Radius, rect.Y, rect.X + rect.Width - (Radius * 2), rect.Y);
            objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y, Radius * 2, Radius * 2, 270, 90);
            objGP.AddLine(rect.X + rect.Width, rect.Y + Radius, rect.X + rect.Width, rect.Y + rect.Height - (Radius * 2));
            objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 0, 90); // Corner

            objGP.CloseFigure();

            g.FillPath(Fill, objGP);
            g.DrawPath(Stroke, objGP);
             }

            #if !PocketPC
             g.DrawString(Marker.ToolTipText, Font, Brushes.Navy, rect, Format);
            #else
             g.DrawString(ToolTipText, ToolTipFont, TooltipForeground, rect, ToolTipFormat);
            #endif
        }
Пример #60
0
        public Font GetAdjustedFont(Graphics GraphicRef, string GraphicString, Font OriginalFont, int ContainerWidth, int MaxFontSize, int MinFontSize, bool SmallestOnFail)
        {
            // We utilize MeasureString which we get via a control instance
            for (int AdjustedSize = MaxFontSize; AdjustedSize >= MinFontSize; AdjustedSize--)
            {
                Font TestFont = new Font(OriginalFont.Name, AdjustedSize, OriginalFont.Style);

                // Test the string with the new size
                SizeF AdjustedSizeNew = GraphicRef.MeasureString(GraphicString, TestFont);

                if (ContainerWidth > Convert.ToInt32(AdjustedSizeNew.Width))
                {
                    // Good font, return it
                    TestFont = new Font(OriginalFont.Name, AdjustedSize-1, OriginalFont.Style);
                    return TestFont;
                }
            }

            // If you get here there was no fontsize that worked
            // return MinimumSize or Original?
            if (SmallestOnFail)
            {
                return new Font(OriginalFont.Name, MinFontSize, OriginalFont.Style);
            }
            else
            {
                return OriginalFont;
            }
        }