Compress font in


New member
Feb 15, 2005
Programming Experience
Is there any way to compress a Font (changing the character's width
while its height remains unchanged) ? I can do it in VB6, but in
VB.Net I couldn't. Here is my code:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Public
Public lfHeight As Integer
Public lfWidth As Integer
Public lfEscapement As Integer
Public lfOrientation As Integer
Public lfWeight As Integer
Public lfItalic As Byte
Public lfUnderline As Byte
Public lfStrikeOut As Byte
Public lfCharSet As Byte
Public lfOutPrecision As Byte
Public lfClipPrecision As Byte
Public lfQuality As Byte
Public lfPitchAndFamily As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Public lfFaceName As String
End Class

Public Shared Function CreateLogFont() As LOGFONT
Dim tmpfont As Font
Dim tmpLogFont As New LOGFONT
tmpfont = New System.Drawing.Font("Courier New", 27.0)
tmpLogFont.lfHeight = 15
tmpLogFont.lfWeight = 10
tmpLogFont.lfWidth = 10
Return tmpLogFont
End Function

After creating tmpLogFont, i created new font for my TextBox

Public Sub New()
Dim lf As New LOGFONT
Dim tmpfont As new Font
tmpfont = tmpfont.FromLogFont(CreateLogFont)
Me.Font = tmpfont
End Sub

The only thing changed is the font height, and the font width
(lfWidth) remains 0!
is there any error in my code?
I tried again, but by using API function CreateFontIndirect, and got
the same result !
Could you give me an example for compressing fonts?

Thank you very much
Best regard.