473,324 Members | 2,473 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,324 software developers and data experts.

Finding the leftmost pixel in a piece of text when using GDI+

I am using GDI+ to generate buttons in my application. Because I want the
left and right edges of the buttons to be a certain number of pixels from
the start and end of the text, I need to know (or be able to calculate) the
left and rightmost pixels of the text. However, this is a problem because
not all letters have their leftmost pixel at the same X position. For
example, when using the following font:

Dim buttonfont As New Font("Arial", 19, FontStyle.Bold, GraphicsUnit.Point)
and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.DrawString(Chr(i), buttonfont, Brushes.White, 0, 35 + (i - 64)
* 20)

Next
The characters 'A' and 'J' start 2 pixels farther to the left than most
other characters (there are also a couple other characters that are offset
by 1 or 2 pixels). Is there any easy way to determine what X position the
first and last pixel of a character is at? Because this depends on the font,
the only way to do it manually would be to test each pixel. Is there a
method that can be used to do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 21 '05 #1
3 987
If this is an offline process, testing each column of pixels should be
enough.

You could also try
http://msdn.microsoft.com/library/de...ntext_52at.asp
and in particular the GLYPHMETRICS structure that should allow to get the
"box" in which the character is drawn...

Patrice
--

"Nathan Sokalski" <nj********@hotmail.com> a écrit dans le message de
news:OC****************@TK2MSFTNGP15.phx.gbl...
I am using GDI+ to generate buttons in my application. Because I want the
left and right edges of the buttons to be a certain number of pixels from
the start and end of the text, I need to know (or be able to calculate) the left and rightmost pixels of the text. However, this is a problem because
not all letters have their leftmost pixel at the same X position. For
example, when using the following font:

Dim buttonfont As New Font("Arial", 19, FontStyle.Bold, GraphicsUnit.Point)

and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.DrawString(Chr(i), buttonfont, Brushes.White, 0, 35 + (i - 64) * 20)

Next
The characters 'A' and 'J' start 2 pixels farther to the left than most
other characters (there are also a couple other characters that are offset
by 1 or 2 pixels). Is there any easy way to determine what X position the
first and last pixel of a character is at? Because this depends on the font, the only way to do it manually would be to test each pixel. Is there a
method that can be used to do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 21 '05 #2
Do you know of anywhere where I can see an example? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Patrice" <no****@nowhere.com> wrote in message
news:Oc**************@TK2MSFTNGP09.phx.gbl...
If this is an offline process, testing each column of pixels should be
enough.

You could also try
http://msdn.microsoft.com/library/de...ntext_52at.asp
and in particular the GLYPHMETRICS structure that should allow to get the
"box" in which the character is drawn...

Patrice
--

"Nathan Sokalski" <nj********@hotmail.com> a écrit dans le message de
news:OC****************@TK2MSFTNGP15.phx.gbl...
I am using GDI+ to generate buttons in my application. Because I want the
left and right edges of the buttons to be a certain number of pixels from
the start and end of the text, I need to know (or be able to calculate)

the
left and rightmost pixels of the text. However, this is a problem because
not all letters have their leftmost pixel at the same X position. For
example, when using the following font:

Dim buttonfont As New Font("Arial", 19, FontStyle.Bold,

GraphicsUnit.Point)


and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.DrawString(Chr(i), buttonfont, Brushes.White, 0, 35 + (i -

64)
* 20)

Next
The characters 'A' and 'J' start 2 pixels farther to the left than most
other characters (there are also a couple other characters that are
offset
by 1 or 2 pixels). Is there any easy way to determine what X position the
first and last pixel of a character is at? Because this depends on the

font,
the only way to do it manually would be to test each pixel. Is there a
method that can be used to do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Nov 21 '05 #3
Try around :
http://cvs.sourceforge.net/viewcvs.p...rm1.cs?rev=1.2

I've done a search using gmBlackBoxX (you could use any other name that
belongs to this structure) on Google...

Good luck.

--
Patrice

"Nathan Sokalski" <nj********@hotmail.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP10.phx.gbl...
Do you know of anywhere where I can see an example? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Patrice" <no****@nowhere.com> wrote in message
news:Oc**************@TK2MSFTNGP09.phx.gbl...
If this is an offline process, testing each column of pixels should be
enough.

You could also try
http://msdn.microsoft.com/library/de...ntext_52at.asp and in particular the GLYPHMETRICS structure that should allow to get the "box" in which the character is drawn...

Patrice
--

"Nathan Sokalski" <nj********@hotmail.com> a écrit dans le message de
news:OC****************@TK2MSFTNGP15.phx.gbl...
I am using GDI+ to generate buttons in my application. Because I want the left and right edges of the buttons to be a certain number of pixels from the start and end of the text, I need to know (or be able to calculate)

the
left and rightmost pixels of the text. However, this is a problem because not all letters have their leftmost pixel at the same X position. For
example, when using the following font:

Dim buttonfont As New Font("Arial", 19, FontStyle.Bold,

GraphicsUnit.Point)


and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.DrawString(Chr(i), buttonfont, Brushes.White, 0, 35 + (i -

64)
* 20)

Next
The characters 'A' and 'J' start 2 pixels farther to the left than most
other characters (there are also a couple other characters that are
offset
by 1 or 2 pixels). Is there any easy way to determine what X position the first and last pixel of a character is at? Because this depends on the

font,
the only way to do it manually would be to test each pixel. Is there a
method that can be used to do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/



Nov 21 '05 #4

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

Similar topics

2
by: Pallavi | last post by:
Hello, Suppose I want to highlight a piece of text. I get the x & y co-ordinates on the screen. And using dhtml I am able to highlight the text. Then I try on another machine with different...
2
by: Bob Palank | last post by:
I think the ability to set a pixel on a graphics surface ought to be straightforward and I tried to illict Dr. Guis opinion but he was too busy to respond. So I think he must agree with me but...
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...
3
by: Nathan Sokalski | last post by:
I am using GDI+ to generate buttons in my application. Because I want the left and right edges of the buttons to be a certain number of pixels from the start and end of the text, I need to know (or...
8
by: **Developer** | last post by:
Seems that Dot.net can not handle files of Indexed Pixel Format as well as other types of formats. Given a file or and Image of type Indexed Pixel Format is there a method to convert it to some...
4
by: Carsten Schmitt | last post by:
Hello, I want to draw a simple pixel (i.e. a red pixel in the center of the screen), which is always in the foreground - even when running a fullscreen application like a DirectX game. I need...
10
by: sklett | last post by:
I have a situation where I'm getting in Image that has a gray (solid, same color) background with a smaller white rectangle inside. The position is not always the same. What I need to do is...
4
by: Martijn Mulder | last post by:
When I zoom in on an image, GDI+ automatically smoothens the edges between the pixels. I am looking for a way to see the individual pixels as squares in the enlarged image, like in MSPaint. I...
4
by: harryos | last post by:
hi i am reading thru a book on digitizing text lines using c code.They use a font data file containing unsigned char fonts with elements like 0x00,0x7e,0x81 etc to represent each character .After...
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.