473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to make C# RichTextBox autosize?

Hi

I need to change RichTextBox size in depend of the text in rtf which contains. Is it possible? RichTextBox in .NET 2.0 does not have autosize and I didn't find other way how to do it.

thanks!

Petr
Oct 4 '06 #1
1 15720
Hi

I need to change RichTextBox size in depend of the text in rtf which contains. Is it possible? RichTextBox in .NET 2.0 does not have autosize and I didn't find other way how to do it.

thanks!

Petr
Hi,

Try the following code on RichTextBox controls TextChanged event

private void rt_TextChanged(object sender, EventArgs e)
{


Font tempFont = ((RichTextBox)(sender)).Font;



int textLength = ((RichTextBox)(sender)).Text.Length;

int textLines = ((RichTextBox)(sender)).GetLineFromCharIndex(textL ength) +1;

int Margin = ((RichTextBox)(sender)).Bounds.Height -((RichTextBox)(sender)).ClientSize.Height;

((RichTextBox)(sender)).Height = (TextRenderer.MeasureText(" ", tempFont).Height * textLines) + Margin +2;
May 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: nouno | last post by:
I am trying to spell check a richtextbox. Through code (shown below) I save the contents of the richtextbox to a rtf file, open the rtf file in Word, spell check it, save it, and then load the ftf...
1
by: Przemyslaw Lopaciuk | last post by:
I want to make RichTextBox very similar to Windows Command Prompt (cmd.exe). It means that I need that nobody can delete the prompt and move cursor in window except in the same line. I use the...
1
by: gabe | last post by:
I am looking for a way to mimic some of the functionality of a web page without writing html (or I am looking to someone to point out something really obvious that I am over looking) Currently I...
2
by: JonnyT | last post by:
I searched high and low for an answer on how to auto scroll a richtextbox and now I finally have it. Since it took me a while to get a good efficient way of doing it that didn't require focus to...
1
by: matthewtech | last post by:
In Visual Studio 2005, using Visual Basic, Is there a way to set the autosize property to false as a standard, and change it to true as needed? Or does it always start out as true when a label ...
8
by: Jordi Rico | last post by:
Hi, I've made the next inherited class in Visual Studio 2005: Public Class LabelEx Inherits System.Windows.Forms.Label Sub New() MyBase.New() Me.ForeColor = Color.Black Me.AutoSize = False...
9
by: James Wong | last post by:
Hi, I use the RichTextBox in my program. It will use different language in this RichTextBox (chinese and english characters), and it set the "DualFont" and use different fonts. By the way, how...
2
by: =?Utf-8?B?Qm9i?= | last post by:
In VB.Net 2003 and previous versions new labels were created with AutoSize=False. In VB.Net 2005, new labels are created with AutoSize=True. Why was it changed? Is there somewhere in VB.Net 2005...
0
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.