Certamente
ecco qua:
Con queste 2 funzioni (Che ho inserito nella mia custom RTB) ricavo il testo della linea "selezionata" dall'inizio alla posizione del cursore di scrittura:
codice:
public string getCurrentLine(string text, int selstart)
{
string r2 = "";
int x = selstart;
r2 = text.Substring(0, x);
int l = r2.LastIndexOf("\n") + 1;
text = r2.Substring(l); ;
l = text.IndexOf("\n");
if (l > -1) text = text.Substring(0, l);
return text;
}
public int getCurrentLineIndex()
{
string lineText = this.getCurrentLine(this.Text, this.SelectionStart);
int lineCount = 0;
foreach (string line in this.Lines)
{
lineCount += 1;
if (line.StartsWith(lineText))
{
return lineCount;
}
}
return 0;
}
Dopo di che grazie a questa (Che ho inserito in un form) ottengo la dimensione del testo:
codice:
int lineCount = r.getCurrentLineIndex();
SizeF size;
using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1)))
{
size = graphics.MeasureString(Charz, r.Font);
}
l.Location = new Point((int)size.Width, 11 * lineCount + 3);