Some GDI/GDI+ fun with the WinForms DataGrid control

I’ve published a new article on MSDN that details how you can add some nifty visual effects to the WinForms DataGrid control when dragging and dropping columns. Constructive criticism is more than welcome. I’m also looking for ideas for my next article, so if there’s anything in the area of GDI/GDI+ that you’re interested in seeing, please don’t hesitate to let me know.

Comments (4)

  1. Daren says:

    Just a thought – you could make the dragged column transparent by using:

    // draw bitmap image

    if ( ShowColumnWhileDragging || ShowColumnHeaderWhileDragging ) {

    float[][] colorMatrixPoints ={

    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, 0.5f, 0},

    new float[] {0, 0, 0, 0, 1}};

    ColorMatrix colorMatrix = new ColorMatrix(colorMatrixPoints);

    ImageAttributes imgAttributes = new ImageAttributes();





    new Rectangle(m_draggedColumn.CurrentRegion.X, m_draggedColumn.CurrentRegion.Y, m_draggedColumn.ColumnImage.Width, m_draggedColumn.ColumnImage.Height),

    0, 0, m_draggedColumn.ColumnImage.Width, m_draggedColumn.ColumnImage.Height,

    GraphicsUnit.Pixel, imgAttributes);

  2. Chris Sano says:

    That’s awesome. Thanks, Daren!

  3. Robert says:

    I’m having a great time with Chris’s data grid. It’s my first time using Microsoft‘s data grid and data sources, and as I keep delving into it, I get more and more pleased. The initial complexity of the control is well worth it when you see what you can do with it.

    The example above (with ColorMatrix) reminds me of something: There really aren’t very good examples of doing all possible manipulations with the ColorMatrix, especially operations involving Matrix Rotations and Shears (like doing gamma corrections, and rotating Hue around the blue axis)

    Fortunately, I remembered Paul Haeberli’s stuff for SGI,

    Also, .Net seems to lack Matrix math fuctions. This is an unfortunate omission. (I wanted to derive my own ColorMatrix to add some of these functions, but the class is "sealed"!)