We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the checkbox size based on DPI?

Platform: WinForms |
Control: GridControl |
Published Date: April 19, 2017 |
Last Revised Date: May 27, 2019

By default, the checkboxsize 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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon