473,830 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Po int)
and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.Dr awString(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********@hotm ail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
3 1250
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********@hot mail.com> a écrit dans le message de
news:OC******** ********@TK2MSF TNGP15.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.Po int)

and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.Dr awString(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********@hotm ail.com
http://www.nathansokalski.com/

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

"Patrice" <no****@nowhere .com> wrote in message
news:Oc******** ******@TK2MSFTN GP09.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********@hot mail.com> a écrit dans le message de
news:OC******** ********@TK2MSF TNGP15.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.Po int)


and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.Dr awString(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********@hotm ail.com
http://www.nathansokalski.com/


Nov 19 '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********@hot mail.com> a écrit dans le message de
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Do you know of anywhere where I can see an example? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Patrice" <no****@nowhere .com> wrote in message
news:Oc******** ******@TK2MSFTN GP09.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********@hot mail.com> a écrit dans le message de
news:OC******** ********@TK2MSF TNGP15.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.Po int)


and using the following lines to draw text:

For i As Integer = 65 To 90

testgraphics.Dr awString(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********@hotm ail.com
http://www.nathansokalski.com/



Nov 19 '05 #4

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

Similar topics

2
9391
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 resolution. I am unable to get the relative position on the screen. Can anyone guide me how to find the relative position on different screen resolutions? Suppose i get the position on 1024 X 768. What would be that position on 800 X 600 or 640 X 480?
2
1446
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 fears authority ;-} What do others think ? ? ? My original email and Dr. Gui's assistants reply is shown below. I'm worried about Dr. GUI and honestly believe he is hoarding the T-Shirts ! In fun
7
3604
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 the bmp1 object? (the pixel location based on the X & Y values and it's color based on the red,blue and green values the I already have)
3
1005
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 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...
4
3119
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 this as an easy entry for programming later a HUD, which shows several informations, like date, time, company logo, etc. Any help or just a simple code example would be appreciated.
10
3704
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 locate the postion and determine the size fo the white rectangle and then crop the image to leave only the white rectangle remaining. I'm very new to GDI+ and have really no idea where to start. Can anyone suggest a good way to accomplish this? ...
4
2882
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 searched in vain in the enumerations System.Drawing.Drawing2D.SmoothingMode and System.Drawing.Drawing2D.InterpolationMode to find the constant that does just that. How? Some code to illustrate the problem: using System.Drawing;
4
1328
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 a text line is scanned 16 times the equivalent codes are stored in an unsigned char bitImage. Now the digitized line stored in bitImage is taken 1 character at a time(ie 8 bits) and color of each is to be determined whether black or white. The...
8
3552
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 Bitmap, change one pixel color and show it, but I'm sure there is another way of doing it. Please help, Ofir.
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10202
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7746
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.