111,128
社区成员
发帖
与我相关
我的任务
分享
var g = e.Graphics;
using (var p = new GraphicsPath())
{
p.AddString("ABC", new FontFamily("Arial"), 1, 15f, new Point(0, 0), new StringFormat());
var b = p.GetBounds();
for (var y = b.Top; y <= b.Bottom; y++)
{
for (var x = b.Left; x <= b.Right; x++)
{
if (p.IsVisible(x, y))
{
g.FillEllipse(Brushes.Red, new RectangleF(x * 10, y * 10, 9, 9));
}
}
}
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
namespace WindowsFormsApplication3
{
public class LEDScreen : Control
{
private int _DotWidth = 10;
[Description("点阵的大小")]
public int DotWidth {
get { return _DotWidth; }
set {
if (value < 0) throw new ArgumentException("点宽度必须大于0");
_DotWidth = value;
this.Width = 0;
this.Invalidate();
}
}
private Size _ScreenSize = new Size(10, 10);
[Description("屏幕分辨率")]
public Size ScreenSize {
get { return _ScreenSize; }
set {
if (value.Width < 0 || value.Height < 0)
throw new ArgumentException("无效的屏幕尺寸");
_ScreenSize = value;
_Swith = new bool[value.Width, value.Height];
this.Width = 0; //触发 SetBoundsCore 函数
this.Invalidate();
}
}
private Color _LigthColor = Color.Red;
[Description("亮灯的颜色")]
public Color LigthColor {
get { return _LigthColor; }
set {
_LigthColor = value;
this.Invalidate();
}
}
private Color _GrayColor = Color.Gray;
[Description("灭灯的颜色")]
public Color GrayColor {
get { return _GrayColor; }
set {
_GrayColor = value;
this.Invalidate();
}
}
private bool[,] _Swith = new bool[10, 10];
public bool[,] Swith {
get { return _Swith; }
}
public LEDScreen() {
this.BackColor = Color.Black;
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
using (SolidBrush sb = new SolidBrush(this._GrayColor)) {
for (int x = 0; x < this._ScreenSize.Width; x++) {
for (int y = 0; y < this._ScreenSize.Height; y++) {
sb.Color = this._Swith[x, y] ? this._LigthColor : this._GrayColor;
g.FillEllipse(sb, x * this._DotWidth, y * this._DotWidth, this._DotWidth, this._DotWidth);
}
}
}
base.OnPaint(e);
}
//代码控制控件的大小
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
width = this._ScreenSize.Width * this._DotWidth + 1;
height = this._ScreenSize.Height * this._DotWidth + 1;
base.SetBoundsCore(x, y, width, height, specified);
}
}
}

就是这样的数字图案!求大神编程实现这张图的数字图案的效果!谢谢