Laden...

RichTextBox Cursor-Position speichern und wiederherstellen

Erstellt von C#ler vor 12 Jahren Letzter Beitrag vor 12 Jahren 3.620 Views
C
C#ler Themenstarter:in
48 Beiträge seit 2011
vor 12 Jahren
RichTextBox Cursor-Position speichern und wiederherstellen

Hallo,
ich habe ein kleines Problem:
Ich möchte Text in einer RichTextBox färben - das geht auch.
Da ich aber in der TextChanged-Methode


richTextBox1.Select(..., ...);
//(...)
richTextBox1.Select(richTextbox1.Text.Length, 0);

verwende, wird der Cursor nach jeder Aktion in der RichTextBox ans Ende gesetzt.
Wie kann ich speichern/feststellen o.ä. wo der Cursor steht bzw. ihn am Ende wieder da hin setzen??
Danke
C#ler

In theory, there is no difference between theory and practice. But, in practice, there is.

The nice thing about the Java API is that if you don't like it, just wait two minutes — it will change. Doug Lyon

F
155 Beiträge seit 2009
vor 12 Jahren

Hallo,

du kannst die Position mit der Eigenschaft SelectionStart bestimmen und verändern.

fz

"We better hurry up and start coding, there are going to be a lot of bugs to fix."

C
C#ler Themenstarter:in
48 Beiträge seit 2011
vor 12 Jahren

Danke, klappt perfekt!


int CursorIndex = richTextBox1.SelectionStart;
//(...)
richtTextBox1.SelectionStart = CursorIndex;

Gruß,
C#ler

In theory, there is no difference between theory and practice. But, in practice, there is.

The nice thing about the Java API is that if you don't like it, just wait two minutes — it will change. Doug Lyon