I use visual basic 2008
I use Groupbox1
In the Groupbox1 in have two labels: label1 and label2.
I have change the font of label1 with properties to size 12
No i change the font size of Groupbox1 with properties to size 8
Only label2 inherit font (8) format from GroupBox1 and label1 inherit not font change

I want that label1 and label2 inherit font from GroupBox1, always!

I how can i do this?

Dani AI

Generated

Short answer: a WinForms control only "inherits" its parent Font when the control itself has no explicit Font value. In your case , Label1 had a design-time Font set (so Visual Studio generated a Font assignment in InitializeComponent), and that explicit value wins over the GroupBox’s Font.

A few safe ways to fix it:

  • Designer reset: select Label1 in the designer, open the Properties window, pick the Font entry and choose Reset (or clear the Font in the Properties window). That removes the designer-serialized Font assignment so the label will use the GroupBox font at design time and runtime. If you prefer, open FormName.Designer.vb, find and remove the Me.Label1.Font = New System.Drawing.Font(...) line, then save and rebuild. Be careful editing designer code — keep a backup.

  • Runtime enforcement: if you want labels to follow GroupBox.Font whenever it changes (even if someone previously set Label.Font), handle the GroupBox.FontChanged event and copy the font to child labels. This is useful when you change the GroupBox font programmatically after startup.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    AddHandler GroupBox1.FontChanged, AddressOf GroupBoxFontChanged
    GroupBoxFontChanged(GroupBox1, EventArgs.Empty)
End Sub

Private Sub GroupBoxFontChanged(sender As Object, e As EventArgs)
    For Each c As Control In GroupBox1.Controls
        If TypeOf c Is Label Then
            Dim fprop = TypeDescriptor.GetProperties(c)("Font")
            ' only update labels that do NOT have a designer-set Font
            If Not fprop.ShouldSerializeValue(c) Then
                c.Font = GroupBox1.Font
            End If
        End If
    Next
End Sub
  • Reusable control: create a small Label subclass that hooks Parent.FontChanged and copies the parent font — handy if you want the behavior on many labels without repeating code.

Note: ’s binding approach works at runtime but won’t change the designer preview; if you need design-time inheritance remove the serialized Font from the label as shown above.

Member Avatar for Member #857553

If you just want to do it from the designer then don't set the font property. If you set the font property then to reset it: Select Label1's Font property and highlight all the font text description and then delete it. That will put it back to its default state and will then inherit the groupbox's font.

If you want to add a binding then you could add one in the load event of the form.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Label1.DataBindings.Add(New Binding("Font", GroupBox1, "Font", False, DataSourceUpdateMode.OnPropertyChanged))
End Sub

That will change the label's font to the groupbox's font when you change the groupbox's font. No matter if you change the label's font or not.

That won't have any affect in the designer though. Only during runtime.

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.