Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ImageInPushButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# How to customize button size in winforms gridcontrol
This example demonstrates how to customize button size in winforms gridcontrol
# How to Set Images on a Pushbutton in WinForms GridControl?

This example demonstrates how to set images on a Pushbutton in [WinForms GridControl](https://www.syncfusion.com/winforms-ui-controls/grid-control).

To set images on a PushButtons in GridControl column, draw the images with a specific size in the [DrawCellButton](https://help.syncfusion.com/cr/windowsforms/Syncfusion.Windows.Forms.Grid.GridControlBase.html#Syncfusion_Windows_Forms_Grid_GridControlBase_DrawCellButton) event.

``` csharp
//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](ImageInPushButton.png)