Posted June 1, 201114 yr 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, 201114 yr by CodeCracker
June 1, 201114 yr 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 }}
June 2, 201114 yr Author 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 { } }
June 2, 201114 yr Yep, set "FlatStyle" to "System".Same for buttons and alike,since they are all "STATIC" controls..
June 2, 201114 yr Author 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
June 2, 201114 yr 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
Create an account or sign in to comment