473,498 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox/RichTextBox - Character(s) width are not same. How to mana

Hello,
I am reading a Column form the DataTable and have to display in the
RichTextBox/TextBox (With Multi-line).

When I try to do so:
The width occupied by each charaters are not same and that causes column
alignment problem.

For ex.

Name Address
---- -------
AAAA NYC
aaaa NYC

Here Both the AAAA and aaaa are 4 in char count, but they are not aligned
because each char occupies its own No. of pixels.

On the other hand, If you copy and past the contant in the notepad, it
aligns properly.

Any suggestion of settings ant attribute to the textbox/RichTextBox?
or Any other control that behaves in the way I expect?

Thanks in advance

With regards
Venkat
Aug 28 '06 #1
3 10130
You need to specify a fixed length font. Try using Courier or Courier New and
things should line up for you.

"Venkatachalam" wrote:
Hello,
I am reading a Column form the DataTable and have to display in the
RichTextBox/TextBox (With Multi-line).

When I try to do so:
The width occupied by each charaters are not same and that causes column
alignment problem.

For ex.

Name Address
---- -------
AAAA NYC
aaaa NYC

Here Both the AAAA and aaaa are 4 in char count, but they are not aligned
because each char occupies its own No. of pixels.

On the other hand, If you copy and past the contant in the notepad, it
aligns properly.

Any suggestion of settings ant attribute to the textbox/RichTextBox?
or Any other control that behaves in the way I expect?

Thanks in advance

With regards
Venkat
Aug 28 '06 #2
use
int iTextWidth = (int) CreateGraphics().MeasureString(strText,
currFont).Width;

to calculate the width that would be occupied by the text 'strText'
when drawn with the font 'currFont'

Alternatively, use TABs

Name\t\t\tAddress
------------------------------------------------------------------------------------
AAAA\t\t\tAAAA's Address
aaaa\t\t\taaaa's Address
Hope that helps

Jared wrote:
You need to specify a fixed length font. Try using Courier or Courier New and
things should line up for you.

"Venkatachalam" wrote:
Hello,
I am reading a Column form the DataTable and have to display in the
RichTextBox/TextBox (With Multi-line).

When I try to do so:
The width occupied by each charaters are not same and that causes column
alignment problem.

For ex.

Name Address
---- -------
AAAA NYC
aaaa NYC

Here Both the AAAA and aaaa are 4 in char count, but they are not aligned
because each char occupies its own No. of pixels.

On the other hand, If you copy and past the contant in the notepad, it
aligns properly.

Any suggestion of settings ant attribute to the textbox/RichTextBox?
or Any other control that behaves in the way I expect?

Thanks in advance

With regards
Venkat
Aug 28 '06 #3
Daanish,
I don't think Venkatachalam cares what the actual lengh of the text is. I
believe he/she only wants to ensure the text lines up correctly.

V,
You have to specify a font that draws each character in the same width.

http://en.wikipedia.org/wiki/Courier_%28font%29

"DaanishRumani" wrote:
use
int iTextWidth = (int) CreateGraphics().MeasureString(strText,
currFont).Width;

to calculate the width that would be occupied by the text 'strText'
when drawn with the font 'currFont'

Alternatively, use TABs

Name\t\t\tAddress
------------------------------------------------------------------------------------
AAAA\t\t\tAAAA's Address
aaaa\t\t\taaaa's Address
Hope that helps

Jared wrote:
You need to specify a fixed length font. Try using Courier or Courier New and
things should line up for you.

"Venkatachalam" wrote:
Hello,
I am reading a Column form the DataTable and have to display in the
RichTextBox/TextBox (With Multi-line).
>
When I try to do so:
The width occupied by each charaters are not same and that causes column
alignment problem.
>
For ex.
>
Name Address
---- -------
AAAA NYC
aaaa NYC
>
Here Both the AAAA and aaaa are 4 in char count, but they are not aligned
because each char occupies its own No. of pixels.
>
On the other hand, If you copy and past the contant in the notepad, it
aligns properly.
>
Any suggestion of settings ant attribute to the textbox/RichTextBox?
or Any other control that behaves in the way I expect?
>
Thanks in advance
>
With regards
Venkat

Aug 29 '06 #4

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

Similar topics

1
5622
by: a_n_d_y_bell | last post by:
Hi- In my application I have a RichTextBox, and I want to scroll it so that the character at a given index appears on the top line of the box. Up till now, I've used this routine, which works...
22
4482
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
4
3055
by: Ed | last post by:
Is there a way to convert a richt text box to a textbox? My code lloks like this Dim txtBox as System.Windows.Forms.TextBo dim richTxtBox as System.Windows.Forms.RichTextBo ...
7
6875
by: Andrew | last post by:
VB .NET 2003, WinXP Pro: Adding text to a text box with the TextBox.AppendText method limits the amount of text in the textbox to 32K. I have a short program that uses the GetFiles function of...
0
11111
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...
4
2887
by: Usmaak | last post by:
Hi, I have a TextBox that is set to a certain width. From this, I need to figure out the max number of characters that can fit into the TextBox. I'm using Courier New font, size 8.25. I've...
4
8185
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...
10
2437
by: garyusenet | last post by:
I have a multiline textbox. The size of the text box should be 75 characters wide, and 5 lines in height like this: - <---75 characters--> <---75 characters--> <---75 characters--> <---75...
1
14310
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
7126
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
7005
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
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7381
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
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.