---
title: "RichTextBox autosize"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/154192-richtextbox-autosize"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "Cactuz"
published: "2006-11-25T01:28:11.000Z"
updated: "2006-11-27T10:33:49.000Z"
replies: 1
views: 374
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/154192-richtextbox-autosize"
---

# RichTextBox autosize

## #1 — Cactuz, 2006-11-25T01:28Z

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.

Permalänk: https://www.webforum.nu/p/154192

## #2 — cok, 2006-11-27T10:33Z

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.

Permalänk: https://www.webforum.nu/p/1902249

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/154192-richtextbox-autosize
