hi
plz share ur thoughts

Dani AI

Generated

already has the right idea using the CellPainting/event for header cells; the usual problems when header text looks "cut" or appears in the divider during a resize are (a) suppressing the grid's border/background painting without redrawing those parts, (b) drawing text into the full cell rectangle (so it overlaps the resize/sort area), or (c) disposing a brush or resource that is reused elsewhere. Let the DataGridView draw borders/background first, paint your image scaled or tiled on top of that, then draw the header text into a slightly inset rectangle and use ellipsis/trimming so it never overlaps the divider or sort glyph.

A simple pattern: call the event-args Paint method to draw Background and Border, fill the header rectangle with your image (use a TextureBrush or DrawImage with a destination rectangle so scaling is explicit), compute an inset text rectangle (subtract a few pixels on the right to avoid the divider and any sort glyph), render the header text with TextRenderer.DrawText using EndEllipsis and VerticalCenter flags, and set e.Handled = true. Use using blocks for brushes you create locally and do not dispose shared brushes/fonts you keep for reuse. See the DataGridView.CellPainting guidance and the TextRenderer.DrawText docs for details and flags: DataGridView.CellPainting event and TextRenderer.DrawText.

If artifacts persist during resize, force a redraw in ColumnWidthChanged/ColumnWidthChanging (InvalidateColumn or Invalidate) and check that DPI scaling or image sizing isn't producing off-by-one pixels. 's stickies are still a good baseline reminder to read the API docs before deeper changes.

Recommended Answers

All 2 Replies

Please read the 2 stickies.

We dont do your work for you, please do some research and come back with a more precise question.

hi Lizr
thnks for great reply.i already implemented the coding but when i resize the colum im char in between the dividerwidth if anybody faced the same probelm with resolution plz tel me the way. i wil do.
c Lizr
this is my coding
celpainting event

if (e.RowIndex < 0)
            {
                Font drawFont = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                                    e.Graphics.DrawImage(Properties.Resources.img1, e.CellBounds);
               
                e.Graphics.DrawString(dataGridView1.Columns[e.ColumnIndex].HeaderText , drawFont, drawBrush, e.CellBounds);
                e.Handled = true;
                drawBrush.Dispose();
                //dataGridView1.Invalidate();

            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.