2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
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
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.
This page will automatically be redirected to the sign-in page in 10 seconds.