I want to change font of all controls in a form.
how i can do this?? i can change font but just for each control not all control in a same time...
please help :)

Dani AI

Generated

As described, the goal is to change every control's font in one go. The attachment from and the loop suggestion from (and the example by ) point in the right direction. A few practical caveats and a small, robust helper make that approach safe and reliable for real WinForms apps.

A handful of things that often get missed: controls inside container controls (Panel, GroupBox, TabPage) need recursive handling; ToolStrip/MenuStrip items are ToolStripItem objects (not plain Controls) and require separate assignment; some third‑party or custom controls may not expose a Font property; and design-time fonts explicitly set on controls may not pick up a simple form-level change. Changing many controls at once can affect layout (AutoSize), so suspend layout while applying the new font.

A concise VB.NET helper that covers nested controls and ToolStrip items (call it from Form.Load) looks like this:

Private Sub ApplyFont(root As Control, f As Font)
    If root Is Nothing Then Exit Sub
    root.SuspendLayout()
    Try
        root.Font = f
        For Each c As Control In root.Controls
            If TypeOf c Is ToolStrip Then
                Dim ts = DirectCast(c, ToolStrip)
                For Each item As ToolStripItem In ts.Items
                    item.Font = f
                Next
            End If
            ApplyFont(c, f)
        Next
    Finally
        root.ResumeLayout()
    End Try
End Sub

' Example call:
' ApplyFont(Me, New Font("Comic Sans MS", 10))

Notes: reuse a single Font instance where possible to reduce GDI allocations; avoid disposing a Font that is assigned to controls; after a mass-change call PerformLayout/Refresh if sizes moved. The thread examples get the basic idea right—these additions handle nested containers and ToolStrip/MenuStrip items and reduce flicker during the update.

Recommended Answers

All 5 Replies

see this attachment :

Change Font.zip

Hope this helps...
PS: don't remove author name n comment

commented: Great code +1
commented: grab this wonderful code +1
commented: good example :) +1
commented: Thanks +2

Try using looping through all the controls on the form that have font property.

commented: a peace logic +1

as debasisdas said,

dim ctlcontrol as object
dim fn as string,fsize as integer

fn="comic sans ms"
fsize=10

on error goto font_mistake

for each ctlcontrol in form1.controls
   ctlcontrol.font=fn
   ctlcontrol.fontsize=fsize
next

exit sub

font_mistake:
   err.clear
   resume next

hope u'll grab some idea.

regards
Shouvik

thanks jx_man. its great program. and debsisdas thx for the logic.

you're welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.