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

G

Guest

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
 
G

Guest

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

DaanishRumani

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top