MeasureText() public méthode

public MeasureText ( string text ) : TextMetrics
text string
Résultat TextMetrics
Exemple #1
0
        public override void Draw(CanvasRenderingContext2D canv)
        {
            if (!Visible) return;
            canv.Save();
            if (!Focused) {
                CursorPosition = -1;
                DragPosition = -1;
            }
            DrawTicks++;
            can = canv;

            canv.StrokeStyle = ButtonBorderGrad;
            canv.FillStyle = Clicking ? Button1Grad : Button2Grad;
            canv.LineWidth = 2;
            Help.RoundRect(canv, TotalX, TotalY, Width, Height, 2, true, true);
            if (canv.Font != Font)
                canv.Font = Font;

            if (DragPosition != -1) {
                canv.FillStyle = "#598AFF";

                var w1 = canv.MeasureText(Text.Substring(0, Math.Min(DragPosition, CursorPosition))).Width;
                var w2 = canv.MeasureText(Text.Substring(0, Math.Max(DragPosition, CursorPosition))).Width;
                canv.FillRect(TotalX + 8 + w1,
                              TotalY + 3,
                              w2 - w1,
                              ( Height - 7 ));
            }
            canv.FillStyle = "#000000";

            int hc;
            if (canv.Font.IndexOf("pt") != -1)
                hc = int.Parse(canv.Font.Substr(0, canv.Font.IndexOf("pt")));
            else
                hc = int.Parse(canv.Font.Substr(0, canv.Font.IndexOf("px")));
            canv.FillText(Text, TotalX + 8, TotalY + ( ( Height - hc ) / 2 ) + Height / 2);

            if (Focused && ( ( blinkTick++ % 35 ) == 0 ))
                blinked = !blinked;
            if (Focused && blinked) {
                canv.StrokeStyle = "#000000";
                var w = canv.MeasureText(Text.Substring(0, CursorPosition)).Width;
                canv.BeginPath();
                canv.MoveTo(TotalX + 8 + w, TotalY + 3);
                canv.LineTo(TotalX + 8 + w, TotalY + ( Height - 7 ));
                canv.LineWidth = 2;
                canv.Stroke();
            }
            canv.Restore();

            base.Draw(canv);
        }