使用GDI+生成KnownColor列表
来源:互联网 发布:淘宝直播的人怎么赚钱 编辑:程序博客网 时间:2024/06/08 19:00
在写这篇“GDI+与WPF中的颜色简析”之前,我试着使用GDI+生成KnownColor列表。现将关键代码贴出来吧。
最终效果图:
现将关键代码:
Bitmap m_Bitmap = null;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (m_Bitmap != null)
{
Graphics g = e.Graphics;
g.DrawImage(m_Bitmap, new Point(0, 0));
}
}
private void btnTestColor_Click(object sender, EventArgs e)
{
int count = 0;
foreach (string s in Enum.GetNames(typeof(KnownColor)))
{
count++;
}
int cols = 4;
int rows = count / cols;
if (count % rows > 0) rows++;
int rectWidth = 100;
int rectHeight = 30;
int wordSpaceFromRect = 10;
int rowSpace = 10;
int marginTop = 20;
int marginBottom = 20;
int width = 300 * cols + 50;
int height = (rectHeight + rowSpace) * rows + marginTop + marginBottom ;
m_Bitmap = new Bitmap(width, height);
Graphics g = Graphics.FromImage(m_Bitmap);
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
g.Clear(Color.White);
Color someColor = Color.FromArgb(0);
Color redShade = Color.FromArgb(255, 200, 0, 100);
SolidBrush myBrush1;
Font myFont = new Font("Arial", 12);
int x = 20;
int y = marginTop;
for (int i = 0; i < count; i++ )
{
someColor = Color.FromKnownColor((KnownColor)i);
myBrush1.Color = someColor;
g.FillRectangle(myBrush1, x, y, rectWidth, rectHeight);
g.DrawRectangle(Pens.Black, x, y, rectWidth, rectHeight);
g.DrawString(someColor.ToString().Replace("Color [","").Replace("]",""), myFont, Brushes.Black, x + rectWidth + wordSpaceFromRect, y);
if (i % cols == cols - 1)
{
y += rectHeight + rowSpace;
x -= 300 * (cols - 1);
}
if (i % cols < cols - 1)
{
x += 300;
}
}
g.Dispose();
this.Invalidate();
}
- 使用GDI+生成KnownColor列表
- 使用GDI+生成数据图
- 使用 GDI+
- 使用GDI+
- GDI+ 使用
- 使用GDI+
- 使用GDI
- gdi使用
- GDI生成图片
- GDI+批量生成图片
- 使用循环列表生成杨辉三角
- 使用VBA生成Excel目录列表
- jquery使用template动态生成列表
- 使用NPOI生成Excel级联列表
- 使用NPOI生成Excel级联列表
- C# GDI生成饼图
- WINAPI使用 GDI作图
- 使用GDI+编程
- 字符集和编码
- 生活
- 2007程序员考试获得省最高分,在此谈谈程序员考试的经验吧
- Java日期
- 2007年8月25日华为的几个面试题
- 使用GDI+生成KnownColor列表
- 函数调用约定
- ★★腾讯永远不敢放出的QQ——60481729★★
- 最新破解QQ空间收费物品的真实地址(完全可免费使用)
- java垃圾收集算法(转)
- autorun.inf
- 指针定义
- 今天的今晚,,,,,
- Index Search Add FAQ Ask Question (SQL*Net, Net8 and Net9)