473,411 Members | 2,530 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,411 software developers and data experts.

Sizing a "RichTextBox"

Hi there,

I have a dialog with a "RichTextBox" that's anchored on all 4 sides of the
dialog. I now want to resize this control in my "OnLoad()" handler so that
it reflects the size of its text. Because of the anchoring, I can do this by
simply resizing the dialog itself. The (condensed) code basically looks like
this:

class MyDialog : Form
{
private RichTextBox m_TextBox;

protected override void OnLoad(EventArgs e)
{
Graphics graphics = m_TextBox.CreateGraphics();
SizeF newTextBoxSize = graphics.MeasureString(m_TextBox.Text,
m_TextBox.Font, CalculateMaxTextWidth());
int newTextBoxWidth = (int)Math.Ceiling(newTextBoxSize.Width);
int newTextBoxHeight = (int)Math.Ceiling(newTextBoxSize.Height);

Width = Width + (newTextBoxWidth - m_TextBox.ClientSize.Width)
Height = Height + (newTextBoxHeight - m_TextBox.ClientSize.Height);
}
}

This works except that the vertical scrollbar now shows up sometimes in
"m_TextBox". If I increase "Height" on the last line by just a few extra
pixels however (sometimes just one), then the vertical scroll bar
disappears. I can't play guessing games however so does anyone know how to
calculate the "Height" so that it always accomodates.the control without a
scrollbar. Thanks.
Jul 31 '07 #1
0 1194

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patrick Blackman | last post by:
Need example of using WinAPI "CreateWindowEx" in c# any help would be appreciated.
5
by: Filip De Backer | last post by:
hi everyone, I want a textbox with word layout. And than save this text to a field in a sql server. how can I do that? thanks for the answers Filip
9
by: John Grandy | last post by:
Open a .sln containing a web-app and receive the "ASP.NET 1.1 not installed .... " error ..... I've never know the root cause of this error. I've always dealt with it by closing the web-app ,...
4
by: Supra | last post by:
value of type "Integer" cannot be convert to system.color Public Sub APIHighlight2(ByVal BgColour As Integer, ByVal FgColour As Integer) SelectionHighlightBackColour(BgColour) Dim rtb As New...
2
by: Supra | last post by:
value of type "Integer" cannot be convert to system.color. in procedure events: Function doColor(ByVal rtb As RichTextBox, ByVal a As String) Dim bColor, fColor, fgcolor, bgcolor As Integer .....
5
by: Noozer | last post by:
Just wondering if it's possible (easy?) to create a "character mode" control that can be included onto a form. Basically I'm looking for a text mode control that uses a fixed width font that...
6
by: Martin Heuckeroth | last post by:
Hi, We are looking for a way to determine the x and y points of the cursor in a richtext box. We made an VB.NET application with a couple of listboxes and one of them is a richtextlistbox....
1
by: Joe HM | last post by:
Hello - I have a GUI that uses a RichTextBox to output text. The problem is that if this box ouput text while hidden behind another window, it is blank when I bring it to the foreground. The...
1
by: Dom | last post by:
This one is a little difficult to explain. I placed a RichTextBox control on my form, I called it chiMain, then I wrote CHITextBox.cs. This class extends the RichTextbox class, and has a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.