Skip to content

Commit 69ed5af

Browse files
authored
Merge pull request #2 from SyncfusionExamples/ES-976509
ES-976509 - Resolve Issues in Public Syncfusion Code Examples for DataGrid XAML Controls
2 parents e5313f8 + e7460f5 commit 69ed5af

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

ImageInPushButton.png

105 KB
Loading

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
1-
# How to customize button size in winforms gridcontrol
2-
This example demonstrates how to customize button size in winforms gridcontrol
1+
# How to Set Images on a Pushbutton in WinForms GridControl?
2+
3+
This example demonstrates how to set images on a Pushbutton in [WinForms GridControl](https://www.syncfusion.com/winforms-ui-controls/grid-control).
4+
5+
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.
6+
7+
``` csharp
8+
//Event Triggering
9+
this.gridControl1.DrawCellButton += GridControl1_DrawCellButton;
10+
11+
//Event Customization
12+
private void GridControl1_DrawCellButton(object sender, GridDrawCellButtonEventArgs e)
13+
{
14+
if (e.Style.CellType == GridCellTypeName.PushButton)
15+
{
16+
Bitmap bitmap = new Bitmap(30, 20);
17+
Rectangle rect = e.Button.Bounds;
18+
if (e.ColIndex == 3)
19+
{
20+
bitmap = new Bitmap(SystemIcons.Error.ToBitmap(), new Size(30, 25));
21+
}
22+
23+
if (e.ColIndex == 7)
24+
{
25+
bitmap = new Bitmap(SystemIcons.Exclamation.ToBitmap(), new Size(20, 20));
26+
}
27+
28+
e.Graphics.DrawImage(bitmap, rect.X + 30, rect.Y, bitmap.Width, bitmap.Height);
29+
e.Cancel = true;
30+
}
31+
}
32+
```
33+
34+
The screenshot below displays the image in pushbuttons.
35+
36+
![Displays image in pushbutton](ImageInPushButton.png)

0 commit comments

Comments
 (0)