示例#1
0
        /// <summary>
        ///     Gets the size of a line specified by it's line number.
        /// </summary>
        public static SizeF GetLineSize(Scintilla scintilla, int lineIndex)
        {
            //
            // TO DO:   read the font settings from DEFAULT, DOCUMENT_DEFAULT, etc and make a sensible choice
            //          for now it is Courier New,10,bold
            float zoom = (scintilla.Zoom <= -10F ? 0.1F : 1 + (float)scintilla.Zoom / 10);

            string indent = "";

            for (int i = 0; i < scintilla.Indentation.IndentWidth; i++)
            {
                indent += " ";
            }

            string strToMeasure = scintilla.Lines[lineIndex].Text;

            strToMeasure = strToMeasure.Replace("\t", indent);

            SizeF sizeF;

            using (Graphics g = scintilla.CreateGraphics())
            {
                var font = new Font("Courier New", zoom * 10, FontStyle.Bold);
                sizeF = g.MeasureString(strToMeasure, font);
            }
            return(sizeF);
        }