Results 1 to 6 of 6

Thread: Form In Panel Inherits Panel Font

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311

    Resolved Form In Panel Inherits Panel Font

    Hi

    If I put a panel1 on form1, set the font of the panel to size 16.

    Add a button to the form1.

    In the click event handler of the button add:

    Code:
            form2.TopLevel = False
            Panel1.Controls.Add(form2)
            form2.Show()
    Create a new form2, draw a button on it.

    Run the project, click the button. Form 2 inherits the font from panel1 and so resizes things.

    Solution at the moment is to set the panel1 to have the font of form2, then reset it when form2 is closed.

    Is there a better way?

    Cheers
    Last edited by Help321; Jan 14th, 2015 at 09:40 PM.
    Why do today what you can tomorrow...

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Form In Panel Inherits Panel Font

    What happens if, right after to do the Controls.Add(form2), manually set form2's font to the font of your choice and then Show() it?

    So:

    vb Code:
    1. form2.TopLevel = False
    2. Panel1.Controls.Add(form2)
    3. form2.Font = New Font(...)
    4. form2.Show()

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311

    Re: Form In Panel Inherits Panel Font

    Thanks. That works and is a better way as there's less code.
    Why do today what you can tomorrow...

  4. #4
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Form In Panel Inherits Panel Font

    Sweet! Glad it worked out for you : ).
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,454

    Re: Form In Panel Inherits Panel Font

    As always, read the documentation first:
    Quote Originally Posted by MSDN
    The Font property is an ambient property. An ambient property is a control property that, if not set, is retrieved from the parent control. For example, a Button will have the same BackColor as its parent Form by default. For more information about ambient properties, see the AmbientProperties class or the Control class overview.
    Sounds rather like the logical thing to do is to set the Font property of the form immediately before adding it to the Panel. If the value is set explicitly then it won't be retrieved from the parent.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2000
    Location
    Sydney
    Posts
    311

    Re: Form In Panel Inherits Panel Font

    Thanks jmcilhinney. Agreed.

    I admit to tunnel vision with this, my thinking being the controls on Form2 have the parent of Form2, I didn't go as far to think that the Form2 would inherit its font from the panel.

    And so it took me a long time, and lots of shouting , to even work why the controls were resizing themselves.
    Why do today what you can tomorrow...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width