当前位置: 首页>>代码示例>>C#>>正文


C# PointD.MultiplyScalar方法代码示例

本文整理汇总了C#中System.Drawing.PointD.MultiplyScalar方法的典型用法代码示例。如果您正苦于以下问题:C# PointD.MultiplyScalar方法的具体用法?C# PointD.MultiplyScalar怎么用?C# PointD.MultiplyScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.PointD的用法示例。


在下文中一共展示了PointD.MultiplyScalar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawLine

        protected void DrawLine(RectangleD worldRect, Rectangle canvasRect, Graphics g,
            Pen pen, BrushesStorage brushes, bool isArrow)
        {
            // получить точки линии (как проекции от края до края экрана или просто точки отрезка)
            PointD[] points;
            if (LineStyle == TrendLineStyle.Отрезок || LineStyle == TrendLineStyle.Стрелка ||
                LineStyle == TrendLineStyle.ОтрезокСМаркерами)
            {
                points = new[] { linePoints[0], linePoints[1] };
            }
            else
            {
                points = new PointD[2];
                if (linePoints[0].X == linePoints[1].X)
                {
                    points[0] = new PointD(linePoints[0].X, worldRect.Bottom);
                    points[1] = new PointD(linePoints[0].X, worldRect.Top);
                }
                else
                {
                    double k = (linePoints[1].Y - linePoints[0].Y) /
                               (linePoints[1].X - linePoints[0].X);
                    double b = linePoints[1].Y - k * linePoints[1].X;
                    points[0] = new PointD(worldRect.Left, worldRect.Left * k + b);
                    points[1] = new PointD(worldRect.Right, worldRect.Right * k + b);
                }
            }
            screenPointA = Conversion.WorldToScreenF(points[0], worldRect, canvasRect);
            screenPointB = Conversion.WorldToScreenF(points[1], worldRect, canvasRect);
            // провести линию
            if (!isArrow)
                g.DrawLine(pen, screenPointA, screenPointB);
            // стрелочка на конце
            else
                DrawArrow(g, pen, screenPointA, screenPointB);
            // если линия декорирована
            if (LineStyle == TrendLineStyle.ОтрезокСМаркерами || LineStyle == TrendLineStyle.ЛинияСМаркерами)
            {
                var length = Math.Sqrt((screenPointA.X - screenPointB.X) * (screenPointA.X - screenPointB.X) +
                             (screenPointA.Y - screenPointB.Y) * (screenPointA.Y - screenPointB.Y));
                if (length > 0)
                {
                    var brushMarker = brushes.GetBrush(pen.Color);
                    var patternStep = 50 * Math.Abs((int)PixelScale);
                    var wholeVector = new PointD(screenPointB.X - screenPointA.X, screenPointB.Y - screenPointA.Y);

                    for (var i = 0; i <= (length - patternStep); i += patternStep)
                    {
                        var a = screenPointA + wholeVector.MultiplyScalar(i / length);
                        var b = screenPointA + wholeVector.MultiplyScalar((i + 1) / length);
                        // нарисовать декоративный элемент, заключенный между точками a-b
                        DrawDecoration(a, b, g, brushMarker);
                    }
                }
            }

            // нарисовать квадратики с текстом в начале и в конце отрезка
            if (ShowTags)
            {
                var brushText = brushes.GetBrush(LineColor);
                var brushFill = brushes.GetBrush(Color.FromArgb(128, ShapeFillColor));

                // начало линии - две строки вида "10.07.2013 22:02, 1.5132", "18.07.2013 13:40, 1.4989"
                const int textPadding = 4;
                var textStart = new List<string>
                    {
                        Owner.Owner.StockSeries.GetCandleOpenTimeByIndex((int) Math.Abs(points[0].X)).ToString("dd.MM.yyyy HH:mm") +
                        ", " +
                        points[0].Y.ToStringUniformPriceFormat(),
                        Owner.Owner.StockSeries.GetCandleOpenTimeByIndex((int) Math.Abs(points[1].X)).ToString("dd.MM.yyyy HH:mm") +
                        ", " +
                        points[1].Y.ToStringUniformPriceFormat()
                    };

                var rect = GetTagRectangle(screenPointA, canvasRect, g, textStart, textPadding,
                    new PointD(points[0].X - points[1].X, points[0].Y - points[1].Y));
                g.FillRectangle(brushFill, rect);
                g.DrawRectangle(pen, rect);

                // текст...
                DrawTagTextLines(g, rect, textPadding, textStart, brushText);

                // кончик линии - текст вида "-0.00206", "-206 пп"
                var delta = points[1].Y - points[0].Y;
                textStart = new List<string>
                    {
                        delta.ToString("f" + DalSpot.Instance.GetPrecision(Owner.Owner.Owner.Symbol)),
                        DalSpot.Instance.GetPointsValue(Owner.Owner.Owner.Symbol, (float)delta).ToStringUniform(1) + " пп"
                    };
                rect = GetTagRectangle(screenPointB, canvasRect, g, textStart, textPadding,
                    new PointD(points[1].X - points[0].X, points[1].Y - points[0].Y));
                g.FillRectangle(brushFill, rect);
                g.DrawRectangle(pen, rect);

                // текст...
                DrawTagTextLines(g, rect, textPadding, textStart, brushText);
            }
        }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:98,代码来源:TrendLine.cs


注:本文中的System.Drawing.PointD.MultiplyScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。