Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2007

Tip: Looking for answers? Try searching our database.

GetCharABCWidths or GetCharABCWidthsFloat analogs in .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexander Smirnov - 31 Aug 2007 11:06 GMT
What methods of what classes I must use in .NET to get the info that
GetCharABCWidthsFloat gives?
Or what is a way to obtain char widths for  the font in .NET ?

Thanks in advance.
Petar Atanasov - 31 Aug 2007 12:20 GMT
> What methods of what classes I must use in .NET to get the info that
> GetCharABCWidthsFloat gives?
> Or what is a way to obtain char widths for  the font in .NET ?
>
> Thanks in advance.

Hi Alex,

You can obtain the char width by MeasureString(...):
    Font font = new Font("Courier New", 12, GraphicsUnit.Pixel);
        float width = font.Size;
        Graphics g = this.CreateGraphics();
        width = g.MeasureString("A", font).Width;
        g.Dispose();

Or just call GetCharABCWidthsFloat:

[DllImport("gdi32", EntryPoint="GetCharABCWidthsFloat")]
public static extern int GetCharABCWidthsFloatA(int hDC, int iFirstChar,
int iLastChar, ref ABCFLOAT lpABCF)

HTH,
Petar Atanasov
http://a-wake.net
Peter Duniho - 31 Aug 2007 18:05 GMT
> What methods of what classes I must use in .NET to get the info that
> GetCharABCWidthsFloat gives?
> Or what is a way to obtain char widths for  the font in .NET ?

I'm not aware of a .NET method that is exactly like
GetCharABCWidthsFloat.  So Peter's suggestion to use p/invoke to simply
use the unmanaged method may be the most appropriate solution.

If you choose to use the Graphics class instead (which I think would be
fine as well), you may find the Graphics.MeasureCharacterRanges() method
more appropriate that Graphics.MeasureString() as was suggested.  With
the former, you can create your own string representing the range of
characters you want, and then get all the widths in a single call rather
than calling MeasureString() repeatedly.

Pete

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.