public int PointToIntPos(TextPoint pos)
{
int y = 0;
int p = 0;
foreach (Row r in this)
{
if (y == pos.Y)
break;
p += r.Text.Length + Environment.NewLine.Length;
y++;
}
// Not sure why but if I paste multiple lines
// then this causes a crash because pos.Y is greater
// than the number of elements available through the []
// operator.
int yToUse = Math.Min(this.Count-1, pos.Y);
return p + Math.Min(pos.X, this[yToUse].Text.Length);
}