Ejemplo n.º 1
0
        private void EstimateLines()
        {
            if (foundlineheight > 0)      // already done
            {
                return;
            }

            int bordersize     = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            int textboxclienth = ClientRectangle.Height - bordersize * 2;           // account for border

            if (Text.HasChars() && Text.Contains("\n"))                             // we need text to sense it
            {
                int sl = TextBox.GetCharIndexFromPosition(new Point(0, 0));
                sl = TextBox.GetLineFromCharIndex(sl);
                for (int i = 1; i < ClientRectangle.Height; i++)
                {
                    int nl = TextBox.GetCharIndexFromPosition(new Point(0, i));     // look to see when line changes.. it may not if only one line
                    nl = TextBox.GetLineFromCharIndex(nl);
                    if (sl != nl)
                    {
                        foundlineheight = i;
                        visiblelines    = textboxclienth / i;                       // gotcha..
                        //System.Diagnostics.Debug.WriteLine("Found line h " + i + " giving " + visiblelines + " " + ((float)textboxclienth / i));
                        return;
                    }
                }
            }

            visiblelines = textboxclienth / (int)(Font.GetHeight() + 1);            // basic estimate
        }
Ejemplo n.º 2
0
        public int EstimateVerticalSizeFromText()
        {
            int lastselpos   = this.Text.Length;
            int numberlines  = (lastselpos >= 0) ? (TextBox.GetLineFromCharIndex(lastselpos) + 1) : 0;
            int bordersize   = (!BorderColor.IsFullyTransparent()) ? 3 : 0;
            int neededpixels = (int)(FontPixels() * numberlines) + bordersize * 2 + 4;      // 4 extra for border area of this (bounds-client rect)

            return(neededpixels);
        }