Here is an excellent article on creating a bitmap from a TrueType Font Character. If you want to create a symbol selection dialog with a ListView, these routines can generate the Bitmap image for the listview items.
http://www.codeproject.com/KB/GDI-plus/TTF_to_bitmap_convert.aspx
This article did more than I needed. I only wanted to create the images for a ListView for all of the characters in a TrueType font. I have boiled down the code from the above article to the following:
Private Sub UpdateSymbolList(fontName as String)
ListView1.Items.Clear()
For i As Integer = 0 To 255
Dim bm As Bitmap = ConvertChar(fontName, i, Color.Blue, 32, 32, 20)
ImageList1.Images.Add(i.ToString, bm)
Next
ListView1.LargeImageList = ImageList1
ListView1.SmallImageList = ImageList1
For i As Integer = 0 To 255
Dim lvi As New ListViewItem
lvi.Text = i.ToString
lvi.ImageKey = i.ToString
ListView1.Items.Add(lvi)
Next
End Sub
Public Shared Function ConvertChar(ByVal fontName As String, _
ByVal charCode As Integer, _
ByVal color As Color, _
ByVal bitmapWidth As Integer, _
ByVal bitmapHeight As Integer, _
ByVal characterSize As Single) As Bitmap
Dim charToDraw As Char = Chr(charCode)
Dim bitmap As New Bitmap(bitmapWidth, bitmapHeight)
Dim g As Graphics = Graphics.FromImage(bitmap)
Dim fnt As Font = New Font(fontName, characterSize, FontStyle.Regular)
Dim textFormat As New StringFormat()
textFormat.Alignment = StringAlignment.Center
textFormat.LineAlignment = StringAlignment.Center
g.DrawString(charToDraw.ToString, fnt, New SolidBrush(color), New RectangleF(0, 1, bitmapWidth, bitmapHeight), textFormat)
g.DrawRectangle(New Pen(Drawing.Color.Black, 1), New Rectangle(0, 0, bitmapWidth - 1, bitmapHeight - 1))
Return bitmap
End Function
This blog is a depository for things I have found regarding VB.NET and C#.NET development (and other things I may need to remember). This blog is primarily for my own reference, but if the information I found is useful to others, then that is great. If others want to contribute with comments or other information, then that is great too.
Showing posts with label Large Fonts. Show all posts
Showing posts with label Large Fonts. Show all posts
Friday, October 24, 2008
Wednesday, June 18, 2008
Disappearing Controls in the Left SplitContainer Panel when using Large Fonts
I have been experiencing a strange problem that I have finally confirmed as a bug in the .NET Framework 2.0. If you are using a SplitContainter and place controls in your Left panel, then if you anchor those controls to the Right or the Bottom, they will disappear when you run the app on a machine that is using Large Fonts. My controls happen to all be in a group box, but I don't think that matters. The controls disappear because the anchor is setting the height and/or width to 0 and they are not visible. If you can drag the size wide or tall enough, the controls will start to appear, but they scaling is off and the anchor is not working correctly. If using Small Fonts, this problem does not exists.
I found a few other people with the same problem, but no solutions. I found one suggestion to do a Refresh on the Splitter move event, but this did not help me. My solution has been to adjust the size of the controls in the left panel myself and not rely on the anchor. Please post a comment if you have a better solution to this problem.
I found a few other people with the same problem, but no solutions. I found one suggestion to do a Refresh on the Splitter move event, but this did not help me. My solution has been to adjust the size of the controls in the left panel myself and not rely on the anchor. Please post a comment if you have a better solution to this problem.
Labels:
Anchor,
Large Fonts,
SplitContainer
Subscribe to:
Posts (Atom)