Skip to content

SyncfusionExamples/how-to-set-images-on-a-pushbutton-in-winforms-grid-control

Repository files navigation

How to Set Images on a Pushbutton in WinForms GridControl?

This example demonstrates how to set images on a Pushbutton in WinForms GridControl.

To set images on a PushButtons in 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.

Displays image in pushbutton

About

This example demonstates how to customize button size in winforms gridcontrol

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6

Languages