   [.net] How to draw a line using the inverse of the background color GDI in C#
  Hello all,I'm trying to figure out how to draw a line using the inverse of the background color GDI in C#.I have a gradient background, and I'm using a Path object to draw a line between a couple of boxes.Is there a brush tha that will draw inverse of a color?  Anybody know some tricks here?Thanks!   
  This was really simple in classic GDI, but in System.Drawing, I don't think there are any alternatives without ugly hacks. How about making a pen which uses an inverted background brush?   ;  Now you made me curious. Yes, GDI+ really lacks some nice-to-have features in this regard. But since you are already using a path, you can do a workaround using a temporary image, a region and ImageAttributes:private void gdiPathPictureBox_Paint2(object sender, PaintEventArgs e){    Rectangle rectangle = new Rectangle(new Point(0, 0), gdiPathPictureBox.Size);    // setup temporary image    Bitmap tempImage = new Bitmap(rectangle.Width, rectangle.Height);    Graphics tempGraphics = Graphics.FromImage(tempImage);    // draw some stuff    tempGraphics.Clear(Color.Gray);    LinearGradientBrush brush = new LinearGradientBrush(new Point(0, 0), new Point(gdiPathPictureBox.Size), Color.LightBlue, Color.DarkGreen);    tempGraphics.FillRectangle(brush, rectangle);    Pen pen = new Pen(Brushes.Red, 20);    tempGraphics.DrawLine(pen, new Point(100, 100), new Point(800, 600));    // setup the region we want to invert (simple line    GraphicsPath linePath = new GraphicsPath(FillMode.Alternate);    linePath.AddLine(new Point(100, 600), new Point(800, 100));    pen = new Pen(Brushes.White, 100);    linePath.Widen(pen);    Region region = new Region(linePath);    // setup image attributes for color negation    ImageAttributes attributes = new ImageAttributes();    float[][] colorMatrixElements = {    new float[] {-1,  0,  0,  0, 0},   new float[] {0,  -1,  0,  0, 0},   new float[] {0,  0,  -1,  0, 0},   new float[] {0,  0,  0,  1, 0},   new float[] {1,  1,  1,  0, 1}};    ColorMatrix matrix = new ColorMatrix(colorMatrixElements);    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);    // final drawing, first the "background" we setup earlier...    e.Graphics.DrawImageUnscaled(tempImage, 0,0);    // ... then invert the region we want    e.Graphics.Clip = region;    e.Graphics.DrawImage(tempImage, rectangle, 0, 0, rectangle.Width, rectangle.Height, GraphicsUnit.Pixel, attributes);    tempImage.Dispose();}Of course, if you want to invert repeatedly you have to double buffer (two temp images), but maybe this is what you want.Hope that helps.unbird   ;  ControlPaint.DrawReversibleLine(Point,Point,Color);The caveat being, it draws using the desktop window context, so if you need to do any clipping you'd have to do it manually. You can also just GDI to do the dirty work, here has some info and reflector will tell you how ControlPaint.DrawReversible* does its thing.   