473,698 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Font.FromLogFon t producing strange results

Hello,

I am having trouble converting a LOGFONT structure to a System.Drawing. Font
object.

I'm calling SystemParameter sInfo to get the LOGFONT lfntSMCaptionFo nt from a
NONCLIENTMETRIC S structure. I seem to be doing this correctly, but when I
try to create a System.Drawing. Font object with the Font.FromLogFon t, the
new Font object has a different Name than the LOGFONT.

Here are the results of my test program (WinXP):

LOGFONT Name: Tahoma
Creating a System.Drawing. Font object from the LOGFONT...
Font Name: Arial

The FaceName of the LOGFONT is "Tahoma" (which is correct), but after using
the Font.FromLogFon t method, the Font object's Name property yields "Arial"

Does anyone have any ideas?

Thanks for any insight, below is the C# source of my test program.

Regards,
-Justin Van Patten
// Test Program Source
using System;
using System.Runtime. InteropServices ;
using System.Drawing;

class Test
{

[StructLayout(La youtKind.Sequen tial)]
public struct LOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public int lfWeight;
public byte lfItalic;
public byte lfUnderline;
public byte lfStrikeOut;
public byte lfCharSet;
public byte lfOutPrecision;
public byte lfClipPrecision ;
public byte lfQuality;
public byte lfPitchAndFamil y;
[MarshalAs(Unman agedType.ByValT Str, SizeConst=32)]
public string lfFaceName;
}

[StructLayout(La youtKind.Sequen tial)]
public struct NONCLIENTMETRIC S
{
public int cbSize;
public int iBorderWidth;
public int iScrollWidth;
public int iScrollHeight;
public int iCaptionWidth;
public int iCaptionHeight;
public LOGFONT lfntCaptionFont ;
public int iSMCaptionWidth ;
public int iSMCaptionHeigh t;
public LOGFONT lfntSMCaptionFo nt;
public int iMenuWidth;
public int iMenuHeight;
public LOGFONT lfntMenuFont;
public LOGFONT lfntStatusFont;
public LOGFONT lfntMessageFont ;
}

[DllImport("User 32.dll")]
public static extern bool SystemParameter sInfo(
int Action, int uiParam,
ref NONCLIENTMETRIC S pvParam, int WinIni);

static void Main()
{

const int SPI_GETNONCLIEN TMETRICS = 41;

try
{

NONCLIENTMETRIC S ncm = new NONCLIENTMETRIC S();
ncm.cbSize = Marshal.SizeOf( ncm);
bool b = SystemParameter sInfo(SPI_GETNO NCLIENTMETRICS, ncm.cbSize, ref ncm,
0);

if (b)
{

// Output The LOGFONT's FaceName
Console.WriteLi ne("LOGFONT Name: \t{0}", ncm.lfntSMCapti onFont.lfFaceNa me);

Console.WriteLi ne("Creating a System.Drawing. Font object from the
LOGFONT...");

// Try to create a System.Drawing. Font object from the LOGFONT
Font SMCaptionFont = Font.FromLogFon t(ncm.lfntSMCap tionFont);

// Output the name
Console.WriteLi ne("Font Name: \t{0}", SMCaptionFont.N ame);

}
else
{
Console.WriteLi ne("Failed");
}

}
catch (Exception ex)
{
Console.WriteLi ne(ex.ToString( ));
}
}
}
Jul 19 '05 #1
1 4178
Justin,
Does anyone have any ideas?


Add CharSet=CharSet .Auto to the StructLayout and DllImport attributes.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 19 '05 #2

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

Similar topics

133
6572
by: Philipp Lenssen | last post by:
Why is there no standardized and well-working way for a web-page to offer the font for download/embed it, in order to be displayed on the page? No matter what you think of the preferred font of a designer, many web-sites offer an image of the text instead to "force" this font -- which certainly can't be the solution (it's a bit of a hassle to maintain and create).
131
21655
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately get some good real world examples. Fire away! :) Regards, Peter Foti
115
7194
by: J | last post by:
I've run CSSCheck on my style sheets and I always get a warning similar to this: "font: bold 9pt/100% sans-serif Warning: Absolute length units should not generally be used on the Web ..." Yet if I use 'x-small' instead of 9pt, I get bigger type on IE6 and smaller type on Mozilla. My choices seem to be:
0
1433
by: Joshua T. Moore | last post by:
I must print with a non-TrueType font for the printer to do specific features. I P/Invoked CreateFont to get the (IntPtr) handle of the font, but System.Drawing.Graphics.DrawString's Font.FromLogFont won't allow non-truetype fonts. Please help. J
2
2392
by: MattC | last post by:
Hi, I am developing a timesheet system that collects information about employees activities. In this I collect details about projects they do work for, what type of work, how long, when etc etc. For distributed data input/storage and display I am happy using ASP.NET. However ther eis one aspect of the project I am not entirely comfortable with, report production. The requirement is to produce 6 or 7 reports that view certain aspects...
1
295
by: Justin Van Patten | last post by:
Hello, I am having trouble converting a LOGFONT structure to a System.Drawing.Font object. I'm calling SystemParametersInfo to get the LOGFONT lfntSMCaptionFont from a NONCLIENTMETRICS structure. I seem to be doing this correctly, but when I try to create a System.Drawing.Font object with the Font.FromLogFont, the new Font object has a different Name than the LOGFONT.
7
43913
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics object. 4. If string size is less than the size of the rectangle, we are done.
1
1596
by: Roger Miller | last post by:
The following program gets a TextCtrl's text attributes and sets them back unchanged. However it reports that the font size is 124, and after resetting the attributes the text becomes that size. That is, the window displays a normal-size "foo" and a gigantic "bar". Anyone know what's going on? This is WxPython 2.6 on Python 2.5 on Windows XP. ----------------------------------
16
1873
by: carlbernardi | last post by:
Hi, I was wondering if there is way use a font that is somehow kept in the code instead of having to load it? I am working on a single script that so far can produce images and html but I have not been able to figure out a way that it can also produce a font. Thanks Carl
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
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,...
1
6528
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
4371
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
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.