Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
410
How do I call DrawElement on RowUIElement?
posted

Here's what I'm trying to do in general.

I want to, upon dragging a row, capture that row as an image and drag that instead of the built-in windows icons.  I've got this working nicely using BitBlt at the moment - to a Bitmap from the current screen and onto a Form.

The only problem is there are cases where my grid is partially hidden inside a splitter panel.  So a part of the row may be hidden at the bottom for example.  So when I start to drag and capture the image at the moment, what happens is it only captures the visible part of the row.  The hidden part becomes blank.

So I thought I'd use RowUIElement.Draw - didn't work so well.  I didn't get anything drawn.

Then I tried DrawElement but that didn't work either.  And I don't know if it's because I didn't fill out UIElementDrawParams struct or what.

What I might try next is use DrawToBitmap on control but that seems like inefficient.

Here's the relevant part:

            RowUIElement rowUi = row.GetUIElement() as RowUIElement;
            System.Diagnostics.Debug.Assert(rowUi != null, "row.GetUIElement() must not be null.");
            RowCellAreaUIElement cellsUi = rowUi.ChildElements[2] as RowCellAreaUIElement;
            // index 0 contains the expand/collapse indicator, 1 contains the row selector
            using (Graphics g = Control.CreateGraphics())
            {
                Bitmap bm = new Bitmap(cellsUi.Rect.Width, cellsUi.Rect.Height, g);
                using (Graphics gbm = Graphics.FromImage(bm))
                {
                    Rectangle r = new Rectangle(Point.Empty, cellsUi.Rect.Size);
                    //cellsUi.Draw(gbm, r, false, AlphaBlendMode.Disabled);
                    UIElementDrawParams drawParams = new UIElementDrawParams();
                    cellsUi.DrawElement(ref drawParams);
                    bm.Save(@"c:\temp\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                    return CreateWindow(gbm, cellsUi.Rect, _selected.Count > 1);
                }
            }