Pixel Width of Char in Web App

S

Sangeeta

Hi,

I have a datagrid where columns are of some fixed pixel size. If any
column text increases the width of column, the plan is to truncate it
till its pixel width becomes less than the coloumn width.

Is there a way to find the size of a char in pixel given the font name
and size. I have tried using System.Drawing.Graphics object, but the
width attribute of the returned fSize object does not return value in
pixels. I am including the code in this mail, can anyone tell me if I
there is another approach or if I am doing this the wrong way.

Thanks,
Sangeeta

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Font ft= new Font("CourierThai", 14);
System.Drawing.Image img = System.Drawing.Image.FromFile
(MapPath
"Images/Deepa.jpg"));
System.Drawing.Graphics gh = System.Drawing.Graphics.FromImage(img);
gh.PageUnit = GraphicsUnit.Pixel;
Response.Write(gh.DpiX);
Response.Write(gh.MeasureString("Test", ft).Width);
Response.Write(ft.SizeInPoints);

}
 
J

Jerry III

You have absolutely no control over what font and at which size the user
will see, so forget about being to able to measure that. If you want to
truncate the overflowing text just use styles, overflow: hidden is the one
you want.

Jerry
 
J

Jerry III

Try the <col> elements in your table (I don't think IE parses overflow on
TDs). Like this:

<div ...> <!-- This is your parent div with overflow: scroll -->
<table>
<col style="overflow: hidden;" span="...">
<tbody>
....
</tbody>
</table>

set the span to how many columns your table has, or just repeat the col that
many times or use styles (which I'd prefer).

Jerry
 
J

Jerry III

Oh and if you set your table-layout style to fixed the clients should use
fixed column widths and just hide the overflow.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top