I would like to change the font size of a DataGridView control at runtime and be able to display the new font size without having to restart the application.
Here's my code for changing the font size.
Is it possible to change font size at runtime ("on-the-fly")?Code:Sub GridColumnFont(myGrid As DataGridView, fontSize As Integer) Dim strMethodName = New System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name '...this procedure's name Dim flgDebug As Boolean = False '...debug/test purposes only Dim f As Font = Nothing Try If flgDebug Then Debug.WriteLine("{0} ({1})", strMethodName, Date.Now) f = New Font(family:=myGrid.Font.FontFamily, emSize:=fontSize, unit:=GraphicsUnit.Point, style:=FontStyle.Regular) For i As Integer = 0 To myGrid.ColumnCount - 1 If myGrid.Columns(i).GetType = GetType(DataGridViewTextBoxColumn) AndAlso myGrid.Columns(i).Visible Then myGrid.Columns(i).DefaultCellStyle.Font = f End If Next Catch ex As Exception HandleError(ex, True) Finally f.Dispose() f = Nothing End Try End Sub




Reply With Quote
