CactuzMedlem sedan okt. 2001670 inlägg Jag försöker få en RichTextBox att ändra storlek så att all text får plats i den utan att det behövs någon scroll. Hur jag än bär mig åt dock så får jag det inte att bli exakt. Man tror ju att (antalet rader) * (typsnittets linespace) borde räcka.
Några tips? Detta är en windows form.
cokMedlem sedan dec. 2005664 inlägg Nått i stil med detta:
Point pos = new Point(0, 0);
int firstIndex = richTextBox1.GetCharIndexFromPosition(pos);
int firstLine = richTextBox1.GetLineFromCharIndex(firstIndex);
pos.X = ClientRectangle.Width;
pos.Y = ClientRectangle.Height;
int lastIndex = richTextBox1.GetCharIndexFromPosition(pos);
int lastLine = richTextBox1.GetLineFromCharIndex(lastIndex);
pos = richTextBox1.GetPositionFromCharIndex(lastIndex);
this.Height = panelTop.Height + (pos.Y) + 20 ;
r: i mitt fall är this en egenskapad kontroll, men du borde utifrån pos.Y kunna fixa till din engen hörjd på textboxen.