资源简介
MCU开发中,显示字体使用了UCDOS中的HZK16,这是查看这类点阵字库的工具
详见:http://blog.csdn.net/mostone/article/details/10415069
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HZK
{
public partial class Form1 : Form
{
System.IO.Stream pFontReadStream;
string pFontFileName;
int pPageNo = 0;
Size pFontSize;
Bitmap pBitmap;
Graphics pGraphics;
FormOpenFontDialog pDialog = null;
static string[] FONT_SIZE_LIST = new string[] { “12x6“ “12x8“ “12x12“ “16x8“ “16x16“ “24x24“ “40x20“ “40x40“ “48x24“ “48x48“ };
public Form1()
{
InitializeComponent();
this.pBitmap = new Bitmap(930 910);
this.pGraphics = Graphics.FromImage(pBitmap);
this.toolStripStatusLabel1.Visible = false;
this.toolStripProgressBar1.Visible = false;
this.comboBox1.Items.AddRange(FONT_SIZE_LIST.ToArray());
}
public static string[] getFontSizeList()
{
return FONT_SIZE_LIST;
}
private Size getSize(string value)
{
return new Size(Int16.Parse(value.Substring(3)) Int16.Parse(value.Substring(0 2)));
}
private void btnPickFont_Click(object sender EventArgs e)
{
if (pDialog == null) pDialog = new FormOpenFontDialog();
if (pDialog.ShowDialog() != DialogResult.OK) return;
pFontReadStream = pDialog.getFontFileStream();
pFontSize = this.getSize(pDialog.getFontSize());
pFontFileName = pDialog.getFontFileName();
this.comboBox1.SelectedIndexChanged -= new EventHandler(this.comboBox1_SelectedIndexChanged);
this.comboBox1.SelectedItem = pDialog.getFontSize();
this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
redraw();
}
private void redraw()
{
pPageNo = 0;
drawPage(pPageNo);
this.toolStripStatusLabel1.Text = String.Format(“{0} Font size:{1}x{2}“ pFontFileName pFontSize.Height pFontSize.Width);
}
private void drawPage(int pageNo)
{
if (pFontReadStream == null) return;
const int space = 5;
const int ox = 50;
const int oy = 20;
Point pt = new Point(ox oy);
pFontReadStream.Position = pageNo * 16 * 16 * (pFontSize.Width == 12 ? 16 : pFontSize.Width) * pFontSize.Height / 8;
pGraphics.Clear(this.pictureBox1.BackColor);
this.toolStripStatusLabel1.Visible = false;
this.toolStripProgressBar1.Visible = true;
List list = new List();
bool eof = false;
int tmp;
for (int row = 0; row < 16; row++)
评论
共有 条评论