Articles in this section
Category / Section

How to set images on a pushbutton in WinForms Grid Control?

1 min read

To set the images on buttons in a WinForms GridControl column, draw the images with a specific size in the DrawCellButton event.

//Event Triggering
this.gridControl1.DrawCellButton += GridControl1_DrawCellButton;

//Event Customization
private void GridControl1_DrawCellButton(object sender, GridDrawCellButtonEventArgs e)
{
    if (e.Style.CellType == GridCellTypeName.PushButton)
    {
        Bitmap bitmap = new Bitmap(30, 20);
        Rectangle rect = e.Button.Bounds;
        if (e.ColIndex == 3)
        {
            bitmap = new Bitmap(SystemIcons.Error.ToBitmap(), new Size(30, 25));
        }

        if (e.ColIndex == 7)
        {
            bitmap = new Bitmap(SystemIcons.Exclamation.ToBitmap(), new Size(20, 20));
        }

        e.Graphics.DrawImage(bitmap, rect.X + 30, rect.Y, bitmap.Width, bitmap.Height);
        e.Cancel = true;
    }
}

 The screenshot below displays the image in pushbuttons.

Set images on buttons in grid column


Sample Link:
 Image size in GridButton


Conclusion

I hope you enjoyed learning about how to set the images in a pushbutton in the WinForms GridControl.


You can refer to WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.


For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.


If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied