孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

笔刷用Pen类表示,使用Pen后,必须释放资源。如下例

private void Form1_Paint(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);

    Pen p = new Pen(Color.Black);
    g.DrawLine(p, 0, 0, 100, 100);
    p.Dispose();
}

可以设置Pen的线宽和对齐方式

private void Form1_Paint(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);

    Pen p = new Pen(Color.Black,3);
    p.Alignment=.PenAlignment.Center;
    g.DrawRectangle(p,3,3,8,7);
    p.Dispose();
}

设置画笔的点划线属性用DashStyle属性

private void Form1_Paint(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);

    Pen p = new Pen(Color.Black,2);
    p.DashStyle = DashStyle.Dash;
    g.DrawLine(p, 3, 3, 100, 3);
    p.Dispose();
}
posted on 2011-05-06 22:51  孤独的猫  阅读(1081)  评论(0编辑  收藏  举报