By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

Pixel Width of Char in Web App

P: n/a
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);

}
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Sangeeta" <sa*************@hotmail.com> wrote in message
news:76**************************@posting.google.c om...
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);

}

Nov 17 '05 #2

P: n/a
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

"Sangeeta" <sa*************@hotmail.com> wrote in message
news:76**************************@posting.google.c om...
Hi Jerry,

I am using a div tag with style overflow auto to get a scroll bar for
the datagrid. At what place should i be specifying style overflow
hidden.

Thanks,
Sangeeta

"Jerry III" <je******@hotmail.com> wrote in message

news:<#c**************@TK2MSFTNGP12.phx.gbl>...
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

"Sangeeta" <sa*************@hotmail.com> wrote in message
news:76**************************@posting.google.c om...
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);

}

Nov 17 '05 #3

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

"Sangeeta" <sa*************@hotmail.com> wrote in message
news:76**************************@posting.google.c om...
Hi Jerry,

I am using a div tag with style overflow auto to get a scroll bar for
the datagrid. At what place should i be specifying style overflow
hidden.

Thanks,
Sangeeta

"Jerry III" <je******@hotmail.com> wrote in message

news:<#c**************@TK2MSFTNGP12.phx.gbl>...
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

"Sangeeta" <sa*************@hotmail.com> wrote in message
news:76**************************@posting.google.c om...
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);

}

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.