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. Image for the cookie policy date
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

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.

For current customers, you can check out our WinForms 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 WinForms GridControl and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal We are always happy to assist you!

 

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.

Up arrow icon

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

Live Chat Icon For mobile