使用画笔和钢笔
来源:互联网 发布:js随机生成英文名字 编辑:程序博客网 时间:2024/04/27 19:56
1. 阴影画笔
HatchBrush hBrush1 = new HatchBrush
(HatchStyle.DashedVertical, Color.Chocolate, Color.Red);
HatchBrush hBrush2 = new HatchBrush
(HatchStyle.DarkDownwardDiagonal, Color.Green, Color.Black);
HatchBrush hBrush3 = new HatchBrush
(HatchStyle.SmallCheckerBoard, Color.BlueViolet, Color.Blue);
g.FillEllipse(hBrush1, 20, 40, 100, 120);
Rectangle rect = new Rectangle(150, 80, 200, 140);
g.FillPie(hBrush3, 40, 20, 200, 40,
g.FillRectangle(hBrush2, rect);
2. Form1_Load事件处理程序:创建一个位图并从此位图创建一个Graphics对象。
private void Form1_Load(object sender,
System.EventArgs e)
{
// Get the full size of the form
fullSize = SystemInformation
.PrimaryMonitorMaximizedWindowSize;
// Create a bitmap using full size
bitmap = new Bitmap(fullSize.Width,
fullSize.Height);
// Create a Graphics object from Bitmap
curGraphics = Graphics.FromImage(bitmap);
// Set background color as form's color
curGraphics.Clear(this.BackColor);
// Default pen and brush button colors
PenBtn.BackColor = Color.Black;
BrushBtn.BackColor = Color.Black;
// Create a new pen and brush as
// default pen and brush
curPen = new Pen(Color.Black);
curBrush = new SolidBrush(Color.Black);
}
3. 选择钢笔和画笔的颜色
private void PenSettings_Click(object sender,
System.EventArgs e)
{
ColorDialog colorDlg = new ColorDialog();
colorDlg.ShowDialog();
PenBtn.BackColor = colorDlg.Color;
}
private void BrushSettings_Click(object sender,
System.EventArgs e)
{
ColorDialog colorDlg = new ColorDialog();
colorDlg.ShowDialog();
BrushBtn.BackColor = colorDlg.Color;
}
4. 窗体的paint事件处理程序
以下代码设置钢笔的Color和Width属性及画笔的Color属性。
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
// Set current pens color
curPen.Color = Color.FromArgb(
Convert.ToInt16(
TransCounter.Value.ToString()),
PenBtn.BackColor.R,
PenBtn.BackColor.G,
PenBtn.BackColor.B);
// Set pen's width
curPen.Width = (float)PenWidthCounter.Value;
// Set current brush's color
curBrush.Color = Color.FromArgb(
Convert.ToInt16(
TransCounter.Value.ToString()),
BrushBtn.BackColor.R,
BrushBtn.BackColor.G,
BrushBtn.BackColor.B);
Graphics g = e.Graphics;
// If dragmode is true, draw selected
// graphics shape
if (dragMode)
{
switch (drawIndex)
{
case 1:
{
g.DrawLine(curPen, curX, curY, x, y);
break;
}
case 2:
{
g.DrawEllipse(curPen,
curX, curY, diffX, diffY);
break;
}
case 3:
{
g.DrawRectangle(curPen,
curX, curY, diffX, diffY);
break;
}
case 4:
{
g.FillRectangle(curBrush,
curX, curY, diffX, diffY);
break;
}
case 5:
{
g.FillEllipse(curBrush,
curX, curY, diffX, diffY);
break;
}
}
}
}
- 使用画笔和钢笔
- 使用钢笔绘制线条和形状
- 钢笔工具的使用
- MFC4.钢笔和刷子
- Android 在Canvas中实现画笔效果(一)--钢笔
- VC api使用画笔和画刷
- 钢笔
- 钢笔
- 如何简单使用钢笔铅笔
- 钢笔的选择和保养
- 绘图基础--使用画笔和画刷绘制网络
- 画笔和透明背景色的画笔
- 画笔的使用
- 使用现有画笔
- 画笔的使用 .
- 使用 Windows 现有画笔
- 使用画笔填充矩形
- GDI+画笔的使用
- 如何将excel文件导入到mssql中(dephi)
- JSP与SQL SERVER的留言本.
- 用.NET建立Office Add-in
- GDI+学习笔记(待续)
- Graphics类
- 使用画笔和钢笔
- 颜色、字体和文本
- 在我什么都没有的时候
- I'm not ivy!
- 矩形和区域
- 我的心情
- Eclipse开发调试RMI指南
- Java 网络编程 学习
- 也说 Web2.0 和 1.0