Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
choosefont (comdlg32)
 
.
Summary
TODO - a short description

C# Signature:

[DllImport("comdlg32.dll", CharSet = CharSet.Auto, EntryPoint = "ChooseFont", SetLastError=true)]
public extern static bool ChooseFont(IntPtr lpcf);

VB Signature:

Declare Function ChooseFont Lib "comdlg32.dll" (TODO) As TODO

User-Defined Types:

LOGFONT

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct CHOOSEFONT
{
     public int lStructSize;
     public IntPtr hwndOwner;
     public IntPtr hDC;
     public IntPtr lpLogFont;
     public int iPointSize;
     public int Flags;
     public int rgbColors;
     public IntPtr lCustData;
     public IntPtr lpfnHook;
     public string lpTemplateName;
     public IntPtr hInstance;
     public string lpszStyle;
     public short nFontType;
     private short __MISSING_ALIGNMENT__;
     public int nSizeMin;
     public int nSizeMax;
}

[Flags]
public enum CHOOSEFONTFLAGS
{
     CF_SCREENFONTS = 0x00000001,
     CF_PRINTERFONTS = 0x00000002,
     CF_BOTH = (CF_SCREENFONTS | CF_PRINTERFONTS),
     CF_SHOWHELP = 0x00000004,
     CF_ENABLEHOOK = 0x00000008,
     CF_ENABLETEMPLATE = 0x00000010,
     CF_ENABLETEMPLATEHANDLE = 0x00000020,
     CF_INITTOLOGFONTSTRUCT = 0x00000040,
     CF_USESTYLE = 0x00000080,
     CF_EFFECTS = 0x00000100,
     CF_APPLY = 0x00000200,
     CF_ANSIONLY = 0x00000400,
     CF_SCRIPTSONLY = CF_ANSIONLY,
     CF_NOVECTORFONTS = 0x00000800,
     CF_NOOEMFONTS = CF_NOVECTORFONTS,
     CF_NOSIMULATIONS = 0x00001000,
     CF_LIMITSIZE = 0x00002000,
     CF_FIXEDPITCHONLY = 0x00004000,
     CF_WYSIWYG = 0x00008000,
     CF_FORCEFONTEXIST = 0x00010000,
     CF_SCALABLEONLY = 0x00020000,
     CF_TTONLY = 0x00040000,
     CF_NOFACESEL = 0x00080000,
     CF_NOSTYLESEL = 0x00100000,
     CF_NOSIZESEL = 0x00200000,
     CF_SELECTSCRIPT = 0x00400000,
     CF_NOSCRIPTSEL = 0x00800000,
     CF_NOVERTFONTS = 0x01000000,
     CF_INACTIVEFONTS = 0x02000000
}

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

LOGFONT logfont = new LOGFONT();

logfont.lfFaceName = "Segoe UI";

IntPtr pLogfont = Marshal.AllocHGlobal(Marshal.SizeOf(logfont));
Marshal.StructureToPtr(logfont, pLogfont, false);

CHOOSEFONT choosefont = new CHOOSEFONT();
choosefont.lStructSize = Marshal.SizeOf(choosefont);
choosefont.nSizeMin = 64;
choosefont.nSizeMax = 64;
choosefont.Flags = (int)CHOOSEFONTFLAGS.CF_SCREENFONTS
     | (int)CHOOSEFONTFLAGS.CF_FORCEFONTEXIST
     | (int)CHOOSEFONTFLAGS.CF_INACTIVEFONTS
     | (int)CHOOSEFONTFLAGS.CF_INITTOLOGFONTSTRUCT
     | (int)CHOOSEFONTFLAGS.CF_SCALABLEONLY
     | (int)CHOOSEFONTFLAGS.CF_USESTYLE;
choosefont.lpLogFont = pLogfont;

IntPtr pChoosefont = Marshal.AllocHGlobal(Marshal.SizeOf(choosefont));
Marshal.StructureToPtr(choosefont, pChoosefont, false);

bool result = ChooseFont(pChoosefont);

Marshal.FreeHGlobal(pChoosefont);
Marshal.FreeHGlobal(pLogfont);

Documentation
ChooseFont on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions