0

I learnt from someone yesterday about graphic paths and a rectangle edge and how I could set a inner excluded rectangle.

But now I want to invalidate just a diagonal line:

using (Graphics g = Graphics.FromHwnd(this.Handle))
{
    if (_RubberLineLastStart.HasValue && _RubberLineLastEnd.HasValue)
    {
        using (GraphicsPath gp = new GraphicsPath())
        {
            Rectangle rt = GetSelectionRectangle(_RubberLineLastStart, _RubberLineLastEnd);
            gp.AddRectangle(rt);
            Region reg = new Region(gp);
            Invalidate(reg, false);
            Update();
        }
    }
}

At the moment I am converting the two points into a rectangle and just invalidating that. But can this be better?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • Note that you can of course use graphicsPath.AddLine and then create a region from it. It will still not make the invalidate faster. Do you actually have a speed problem or are you just curious? – TaW Jun 04 '16 at 21:14
  • 1
    Also note that Invalidate is not about clearing or erasing anything. It is about triggering the Paint event. And passing a rectangle (or region) into it will also not make the Paint event draw only a part of the surface. The event always draw everything. Instead it may optimize the drawing speed by moving only a part of the total surface from the memory into the graphics card's memory. This IO operation is rather slow compared to chaning the pixel in memory. So the technique from the linked solution may indeed make a difference in speed.. – TaW Jun 04 '16 at 21:36

0 Answers0