日期:2014-05-18 浏览次数:21511 次
private void button3_Click(object sender, EventArgs e) { //显示按钮 var data = textBox2.Text.Select(x => x == '1').Concat(Enumerable.Repeat(false, 256)) .Take(256).ToArray(); Graphics g = pictureBox1.CreateGraphics(); for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { Brush brush = data[j * 16 + i] ? Brushes.Blue : Brushes.White; g.FillRectangle(brush, new Rectangle() { X = i * 16, Y = j * 16, Width = 16, Height = 16 }); } } } private void button1_Click(object sender, EventArgs e) { //字体设置 FontDialog fd = new FontDialog() { Font = textBox1.Font, FontMustExist = true }; if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { textBox1.Font = fd.Font; } } private void button2_Click(object sender, EventArgs e) { //产生字模 Bitmap bmp = new Bitmap(16, 16); Graphics g = Graphics.FromImage(bmp); g.FillRectangle(Brushes.White, new Rectangle() { X = 0, Y = 0, Height = 16, Width = 16 }); g.DrawString(textBox1.Text, textBox1.Font, Brushes.Black, new PointF() { X = Convert.ToSingle(domainUpDown1.Text), Y = Convert.ToSingle(domainUpDown2.Text) }); textBox2.Text = string.Join("", Enumerable.Range(0, 256).Select(a => new { x = a % 16, y = a / 16 }) .Select(x => bmp.GetPixel(x.x, x.y).GetBrightness() > 0.5f ? "0" : "1")); button3.PerformClick(); } private void textBox1_TextChanged(object sender, EventArgs e) { //输入文字的文本框 textBox1.Text = textBox1.Text.Length > 0 ? textBox1.Text.Substring(textBox1.Text.Length - 1) : ""; textBox1.SelectionStart = textBox1.Text.Length; } private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e) { //微调,用来设置偏移 button2.PerformClick(); } private void domainUpDown2_SelectedItemChanged(object sender, EventArgs e) { button2.PerformClick(); }
// 修改字体 private void button1_Click(object sender, EventArgs e) { if (fontDialog1.ShowDialog() == DialogResult.OK) textBox1.Font = fontDialog1.Font; } // 生成字模 private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text)) return; Bitmap bmp = new Bitmap(1