473,385 Members | 1,569 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,385 software developers and data experts.

Set RichTextBox width based on contents

I would like to load a file to the .Rtf property of a RichTextBox, and then
set the containing form (if possible, depending on screen resolution) to the
smallest width that will not cause the horizontal scrollbar to appear.

Now the RichTextBox must know what width will cause the horizontal scrollbar
to disappear because, after all, the scrollbar does disappear if you make it
wide enough (the RichTextBox is docked to the form.) Any idea how my code
can get that information? I have actually tried to calculate it by grabbing
the Graphics object of the RichTextBox and using MeasureString() on the
longest line, but that did not give the right answer, plus it should not be
necessary... the control has to have this information already I would think.
(If it were a ScrollableControl, it would be AutoScrollMinSize.Width, but
it's not...)

-Rachel
Nov 17 '05 #1
1 2056
"Rachel Suddeth" <ra****@bldhound.com> wrote in message
news:uq*************@TK2MSFTNGP10.phx.gbl...
I would like to load a file to the .Rtf property of a RichTextBox, and then set the containing form (if possible, depending on screen resolution) to the smallest width that will not cause the horizontal scrollbar to appear.

Here's a thought...
Would it work if I used interop with GetScrollRange? Like this:
----
[ DllImport( "user32", CharSet=CharSet.Auto ) ]
public static extern bool GetScrollRange( IntPtr hWnd, int nBar,
out int lpMinPos, out int lpMaxPos );

....
GetScrollRange( richTextBox1.Handle, SB_HORZ, out min, out max );
---
Would the "max" value for the horizontal ScrollRange give me the width I'd
need to avoid scrolling? I'm not familiar with the function, this is purely
guessing. And if it did, would it matter if the form that displayed the
control was loaded first? And what would happen if it was already wide
enough and the scrollbar wouldn't appear anyway? Anyone know?

-Rachel
Nov 17 '05 #2

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

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...
2
by: WoodBeeProgrammer | last post by:
How come everybody on this newsgroup answers easy questions but not hard questions? Does PrintWindow work with RichTextBox? If not, WHY NOT? And if not, what's the workaround? TIA
0
by: Matt | last post by:
This took way to long to figure out - now that I have it working I thought I would share with the group. I've seen tons of posts with very little good answers on this seemingly simple thing that...
1
by: tulasi | last post by:
I am placing textbox controls and combo box controls on richtext box and 2 command buttons on form control. after executing the application i'll place some text into textbox controls and select a...
0
by: Vincent | last post by:
Dear all, I have implemented a class to export the content of RichTextBox to image in WYSISYG mode so that line breaks on the screen are the same as exported. C# Code: public struct...
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...
4
by: Technical | last post by:
Greetings, I am currently working on a project that requires that the contents of a RichTextBox control be drawn to a bitmap. I have attempted nearly everything including using calls into the...
1
by: papalarge | last post by:
Hey all... I've been using the following to calculate the height the textbox needs to be in order to grow it vertically to its necessary size. textbox1.Height =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.