Alignment属性
问题描述:
当我想用钢笔工具如果矩形的宽度和高度小于笔宽度,则程序从如果笔对准财产得出什么插图绘制在C#中的矩形。但是当我设置对齐中心然后它打印一个矩形。这不是我矩形的大小。其实当时发生了什么?Alignment属性
例如:
Pen p = new Pen(Color.Black, 300);
p.Alignment = PenAlignment.Center;
g.DrawRectangle(p, 100, 100,10, 10);
p.Dispose();
输出数字是:
但它是如何可能得出1O像素宽度,HIGHT的矩形300像素的笔宽度?
答
所以,基本上,当矩形宽度或高度小于300px,你想绘制一个黑色填充矩形?
void DrawRectangle(Graphics g, Color pencolor, int penwidth, Rectangle x)
{
if(x.Width < penwidth || x.Height < penHeight)
{
Pen p = new Pen(pencolor);
p.Alignment = PenAlignment.Inset;
g.FillRectangle(p, x);
p.Dispose();
}
else
{
Pen p = new Pen(pencolor, penwidth);
p.Alignment = PenAlignment.Inset;
g.DrawRectangle(p, x);
p.Dispose();
}
}
希望有所帮助。
这就像用扫帚绘画蒙娜丽莎,并问如何获得微笑。 – 2012-02-11 17:45:20