Ejemplo n.º 1
0
        public int GetLine(Point point, IntPtr hdc)
        {
            if (point.Y < 0)
            {
                return(-1);
            }

            int y = 0;

            for (int i = 0; i < myLines.Count; i++)
            {
                RichText line = (RichText)myLines[i];

                y += (int)line.GetSize(hdc).Height;

                if (y > point.Y)
                {
                    return(i);
                }
            }

            return(-1);
        }
Ejemplo n.º 2
0
        public static RichTextBlock Format(RichText text, int width, IntPtr hdc)
        {
            RichTextBlock block = new RichTextBlock(new RichTextBlockParameters(1));

            while (text.GetSize(hdc).Width >= width)
            {
                int[]      positions = GetPossibleDivisionOffsets(text.Text);
                RichText[] parts, oldParts;

                oldParts = new RichText[] { text, new RichText("", text.Parameters) };

                foreach (int position in positions)
                {
                    parts = text.Split(position);

                    if (parts[0].GetSize(hdc).Width > width)
                    {
                        break;
                    }

                    oldParts = parts;
                }

                block.AddLine(oldParts[0]);

                if (oldParts[0].Length == 0) // prevent endless loop
                {
                    break;
                }

                text = oldParts[1];
            }

            block.AddLine(text);

            return(block);
        }