'To set the CheckBox size
Dim renderer As GridCheckBoxCellRenderer = TryCast(Me.gridControl1.CellRenderers("CheckBox"), GridCheckBoxCellRenderer)
renderer.CheckBoxSize = New Size(30, 30) |
'Creating instance for GridDropDowMonthCalendarCellModel
Dim model As GridDropDownMonthCalendarCellModel = TryCast(Me.gridControl1.CellModels("MonthCalendar"), GridDropDownMonthCalendarCellModel)
'Setting the size to Button
model.ButtonBarSize = New Size(30, 30) |
Private renderer As GridDropDownMonthCalendarCellRenderer
renderer = TryCast(Me.gridControl1.CellRenderers("MonthCalendar"), GridDropDownMonthCalendarCellRenderer)
'Event Triggering
AddHandler gridControl1.CurrentCellShowingDropDown, AddressOf GridControl1_CurrentCellShowingDropDown
'Event Customization
Private Sub GridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs)
Dim currentCell As GridCurrentCell = Me.gridControl1.CurrentCell
If TypeOf currentCell.Renderer Is GridDropDownMonthCalendarCellRenderer Then
For Each control As Control In renderer.DropDownContainer.Controls
If control IsNot Nothing Then
control.Font = New Font("Segoe UI", 15f)
e.Size = New Size(310, 310)
End If
Next control
End If
End Sub |
Namespace CellGrid_2008
Friend NotInheritable Class Program
Private Sub New()
End Sub
<STAThread> _
Shared Sub Main()
'Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class
End Namespace |
Query |
Response |
is there a way to set the dropdown calendar size automatically to allow for different font sizes and DPI settings?
I have tried calculating the height and width, but it doesn't work well. I assume there's some way of getting the bounds of the internal controls to set the size?
|
By default the DropDownContainer size will not be changed based on DPI. In order to change the DropDownContainer size automatically for different DPI CurrentCellShowingDropDown event can be customized. In that event, Size property can be used to set the size for the drop down control based on DPI. Please make use of below code and sample,
Dim defaultDPI As Single = 96 'default dpi for 100DPI
Dim currentDPI As Single
Using g As Graphics = Me.CreateGraphics()
currentDPI = g.DpiX
If currentDPI <> defaultDPI Then
'To get the scalefactor for different DPI
scalefactor = currentDPI / defaultDPI
End If
End Using
'Event Triggering
AddHandler gridControl1.CurrentCellShowingDropDown, AddressOf GridControl1_CurrentCellShowingDropDown
'Event Customization
Private Sub GridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs)
Dim currentCell As GridCurrentCell = Me.gridControl1.CurrentCell
If TypeOf currentCell.Renderer Is GridDropDownMonthCalendarCellRenderer Then
For Each control As Control In renderer.DropDownContainer.Controls
If control IsNot Nothing Then
Dim fontSize As Single = gridControl1.BaseStylesMap("Standard").StyleInfo.Font.Size
control.Font = New Font("Segoe UI",(fontSize*scalefactor))
Dim width As Single = (e.Size.Width * scalefactor)
Dim height As Single = (e.Size.Height * scalefactor)
'To set the size for DropDown container based on DPI.
e.Size = New Size(CInt(Fix(width)), CInt(Fix(height)))
End If
Next control
End If
End Sub
|
is it possible to change the visual style of the calendar to make it look the same as it was before visual styles were disabled? |
Yes, the VisualStyle of the calendar can be changed as same as before by enabling the Application.EnableVisualStyles() inside of the program.cs file. Please refer the below code,
Namespace CellGrid_2008
Friend NotInheritable Class Program
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function SetProcessDPIAware() As IntPtr
End Function
Private Sub New()
End Sub
<STAThread> _
Shared Sub Main()
SetProcessDPIAware()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class
End Namespace
Note:
If you include the EnableVisualStyles in program.cs , the appearance customization(calendar size and font size, etc)of the MonthCalendar will not be worked.
Please let us know if we misunderstood anything. |