Articles in this section
Category / Section

How to change the checkbox size based on DPI?

2 mins read

By default, the WinForms Gridcontrol will not be changed based on current DPI. So, checkbox will be drawn with the default size in all DPI. In order to change the CheckBox size based on the current DPI, the CheckboxSize property of GridCheckBoxCellRenderer class can be used.

Code Snippet

C#

//To change the CheckBox size based on DPI.
GridCheckBoxCellRenderer renderer = this.gridControl1.CellRenderers["CheckBox"] as GridCheckBoxCellRenderer;
System.Drawing.Size checkboxSize = renderer.CheckBoxSize;
//Default DPI
float defaultDpi = 96;
float currentDpi;
using (Graphics g = this.CreateGraphics())
{
    currentDpi = g.DpiX;
    if (currentDpi != defaultDpi)
    {
        float scalefactor = currentDpi / defaultDpi;
        renderer.CheckBoxSize = new Size((int)(scalefactor * checkboxSize.Width), (int)(scalefactor * checkboxSize.Height));
    }
}

 

VB

'To change the CheckBox size based on DPI.
Dim renderer As GridCheckBoxCellRenderer = TryCast(Me.gridControl1.CellRenderers("CheckBox"), GridCheckBoxCellRenderer)
Dim checkboxSize As System.Drawing.Size = renderer.CheckBoxSize
'Default DPI
Dim defaultDpi As Single = 96 
Dim currentDpi As Single
Using g As Graphics = Me.CreateGraphics()
    currentDpi = g.DpiX
    If currentDpi <> defaultDpi Then
        Dim scalefactor As Single = currentDpi / defaultDpi
            renderer.CheckBoxSize = New Size(CInt(Fix(scalefactor * checkboxSize.Width)), CInt(Fix(scalefactor * checkboxSize.Height)))
    End If
End Using

 

Screenshot

Showing change the CheckBox size

 

Note:

The CheckBoxsize can also be changed in GridGroupingControl for current DPI as the same way.

 

Getting the GridCheckBoxCellRenderer

C#

GridCheckBoxCellRenderer renderer = this.gridGroupingControl1.TableControl.CellRenderers["CheckBox"] as GridCheckBoxCellRenderer;

 

VB

Dim renderer As GridCheckBoxCellRenderer = TryCast(Me.gridGroupingControl1.TableControl.CellRenderers("CheckBox"), GridCheckBoxCellRenderer)

 

Sample Link:

C#: CheckBoxSize_CS 

VB: CheckBoxSize_VB

 

Conclusion

I hope you enjoyed learning about how to change the checkbox size based on DPI.

You can refer to our WinForms GridControl‚Äôs feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.

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 comments below. You can also contact us through our support forumsDirect-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