-
Jan 14th, 2015, 09:06 PM
#1
Thread Starter
Hyperactive Member
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...
-
Jan 14th, 2015, 09:16 PM
#2
Frenzied Member
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:
form2.TopLevel = False Panel1.Controls.Add(form2) form2.Font = New Font(...) form2.Show()
Justin
-
Jan 14th, 2015, 09:23 PM
#3
Thread Starter
Hyperactive Member
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...
-
Jan 14th, 2015, 09:30 PM
#4
Frenzied Member
Re: Form In Panel Inherits Panel Font
Sweet! Glad it worked out for you : ).
-
Jan 14th, 2015, 09:42 PM
#5
Re: Form In Panel Inherits Panel Font
As always, read the documentation first:
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.
-
Jan 14th, 2015, 09:49 PM
#6
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|