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

Pixel Width of Char in Web App

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
3 2372
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Veerle | last post by:
Hi, I have 2 div blocks with each div taking up half of the page width. So in the CSS they both have width: 50%. See http://home.scarlet.be/~vv991306/leftright.html In Mozilla Firefox and...
4
by: Pat Keel | last post by:
Hi there, Im looking for a solution to draw a one pixel sized point to a graphics control. E.g. DrawLine(10,10, 11,11) draws 2 pixels, DrawLine(10,10, 10,10) has no effect. How to do? Thanks Pat
7
by: TomHL | last post by:
hello, - I have a Bitmap Object named: bmp1 - I already have the numerical values of:red,blue and green colors + I have the X and Y cordinates. How do I set the pixel value via safe code on...
2
by: victor | last post by:
hello, I have several arrays containing (image-) pixel data; I want to display it onto a PictureBox. What is the best Graphics method for it? (MSDN examples talks only about loading it from...
2
by: Daniel | last post by:
Hi, <asp:TableCell BackColor="#000066" ID="tblcell" Width=?/> ? = source from database The problem is, i dont know how to cast the data(from source) to unit.pixel. Have any ideas?
28
by: Alan Silver | last post by:
Hello, Here I am again with another "why does IE do that" question!! Please have a look at http://www.kidsinaction.org.uk/fd/homepage.html and see if you can work out why IE adds a one pixel...
3
by: Bart Van der Donck | last post by:
Hello, I'm having a hard time trying to configure printed output that consists of multiple pages. The idea is the following: <div style=" border: 1px solid blue; position: absolute; top:...
8
by: ofiras | last post by:
Hi, I made a "Paint" program, but I couldn't find a method to paint 1 pixel using graphic state ("Graphics g = Graphics.FromHwnd(this.Handle);") How can I paint 1 pixel? I guess I can make a...
1
by: ofiras | last post by:
In bitmap, how can I find the nearest pixel (pixel 1) to a specific pixel (pixel 2) that has different color from pixel 2? Or how can I find a pixel in a specific distance from pixel 2 (like a...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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
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
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...

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.