CodeExplorer Posted June 1, 2011 Posted June 1, 2011 (edited) How to Print the ASCII Character Set in Visual Basic/>http://support.microsoft.com/kb/75857Using A Standard Terminal Font - documentationStockFont.zip - source example VBStockFont.zipUsing A Standard Teriminal Font.unlocked.pdf Edited June 1, 2011 by CodeCracker
Ufo-Pu55y Posted June 1, 2011 Posted June 1, 2011 Here's a different approach I've put together in thepast to get the 'Terminal' font into a .NET control:public class TerminalBox : TextBox{ [StructLayout(LayoutKind.Sequential)] public class LOGFONT { public const int LF_FACESIZE = 32; 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 lfPitchAndFamily; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FACESIZE)] public string lfFaceName; } [DllImport("gdi32", CharSet = CharSet.Auto)] public static extern uint CreateFontIndirectA([In, MarshalAs(UnmanagedType.LPStruct)]LOGFONT lplf); [DllImport("user32")] static extern void SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam); protected override void OnCreateControl() { base.OnCreateControl(); LOGFONT lfFont = new LOGFONT(); lfFont.lfHeight = 9; lfFont.lfCharSet = 1; // DEFAULT_CHARSET lfFont.lfFaceName = "Terminal"; uint nfoFont = CreateFontIndirectA(lfFont); SendMessage(this.Handle, 0x00000030, nfoFont, 0x00000001); // hWnd, WM_SETFONT, hFont, [redraw=]true }}
CodeExplorer Posted June 2, 2011 Author Posted June 2, 2011 Here is my old code, it require linedraw.ttf.[DllImport ( "Shell32.DLL" )]static extern int SHGetSpecialFolderLocation(IntPtr hwndOwner,int nFolder, out IntPtr ppidl);[DllImport ( "Shell32.DLL" )]public static extern Int32 SHGetPathFromIDList(IntPtr pidl, // Address of an item identifier list thatStringBuilder pszPath);// Get the font path:public string GetFontPath(){FileInfo[] cdirfonts=null;FileInfo[] fontfiles=null;try{ DirectoryInfo curdi = new DirectoryInfo(Environment.CurrentDirectory); cdirfonts = curdi.GetFiles("*.ttf"); foreach(FileInfo fi in cdirfonts) { if (fi.Name.ToLower()=="linedraw.ttf") return fi.FullName; }}catch{}try{IntPtr pidl = IntPtr.Zero;string FontDirectory="";if( 0 == SHGetSpecialFolderLocation(IntPtr.Zero,20, out pidl ) ) // 20 = Font Directory{// Then retrieve the path from the IDList.StringBuilder sb = new StringBuilder ( 1000 );SHGetPathFromIDList(pidl, sb );FontDirectory=sb.ToString();} DirectoryInfo curdi = new DirectoryInfo(FontDirectory); fontfiles = curdi.GetFiles("*.ttf"); foreach(FileInfo fi in fontfiles) { if (fi.Name.ToLower()=="linedraw.ttf") return fi.FullName; }}catch{}return "";}// Now seeting the font: string fontpath = GetFontPath(); if (fontpath!=null&&fontpath!=""&&File.Exists(fontpath)) { try { PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile(fontpath); FontFamily terminal = pfc.Families[0]; Font fontTerminal = new Font(terminal, 12f, FontStyle.Regular, GraphicsUnit.Pixel); txt_scroller.Font = fontTerminal; } catch { } }
CodeExplorer Posted June 2, 2011 Author Posted June 2, 2011 @Ufo-Pu55y:Your code doesn't seems to work for a labelAny idea why ?
Ufo-Pu55y Posted June 2, 2011 Posted June 2, 2011 Yep, set "FlatStyle" to "System".Same for buttons and alike,since they are all "STATIC" controls..
CodeExplorer Posted June 2, 2011 Author Posted June 2, 2011 Works fine now thanks. Now I have another problem with the Terminal font: Autosize doesn't work properly; so I should compute the size on my own, I looked on " INFO: Calculating The Logical Height and Point Size of a Font"/>http://support.microsoft.com/kb/74299 and I'm quite confuse
Ufo-Pu55y Posted June 2, 2011 Posted June 2, 2011 I don't know w/o investigating, and to be honest I would simplynever use such a font, if it's not for a textbox to show NFO chars!But if you're just doing it out of curiosity, then I guess youshould take a look at following API calls instead:SIZE size;IntPtr hDC = GetDC(someForm.Handle);GetTextExtentPoint(hDC, someString, Len(someString), ref size);ReleaseDC(someForm.Handle, hDC);..'size' should contain height and width of the string in pixels
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now