0

我需要绘制一个带有Graphics类的网格(只是交叉线),以及像这张图片这样的透明表示:

在此处输入图像描述

除了绘制每条线/矩形之外,我不知道任何其他方式。如果领域很宽,性能会很差。有没有更好的方法来绘制这些东西?

这是我当前绘制网格的代码:

    private void drawGrid(Graphics pGraphic, int pGridSize)
    {
        int verticalCount = this.mPicScreen.Width / pGridSize + 1;
        int horizontalCount = this.mPicScreen.Height / pGridSize + 1;

        Pen p = new Pen(Color.Gray);

        // Vertical Lines
        for (int i = 0; i < verticalCount; i++)
        {
            pGraphic.DrawLine(p,
                new Point(i * pGridSize, 0),
                new Point(i * pGridSize, this.mPicScreen.Height));
        }

        // Horizontal Lines
        for (int i = 0; i < horizontalCount; i++)
        {
            pGraphic.DrawLine(p,
                new Point(0, i * pGridSize),
                new Point(this.mPicScreen.Width, i * pGridSize));
        }
    }
4

2 回答 2

3

有一个更好的方法:只用刷子

如果您需要制作用户定义的网格大小,您可以使用

System.Drawing.TextureBrush 

如果一个随机的没问题,你会发现

System.Drawing.Drawing2D.HatchBrush 

已经是网格样式

于 2012-08-20T04:12:19.973 回答
0

该控件实际上在绘制过程中闪烁(因为该控件被故意无效)。这不是性能问题,而是实际上因为控件不是DoubleBuffered.

这是启用的DoubleBuffered代码Controls

public static void setDoubleBuffered(System.Windows.Forms.Control c)
{
    if (System.Windows.Forms.SystemInformation.TerminalServerSession)
        return;

    System.Reflection.PropertyInfo aProp =
          typeof(System.Windows.Forms.Control).GetProperty(
                "DoubleBuffered",
                System.Reflection.BindingFlags.NonPublic |
                System.Reflection.BindingFlags.Instance);

    aProp.SetValue(c, true, null);
}
于 2012-08-20T03:23:46.133 回答