Problem with usercontrol scaling when added at run-time in .Net, WinForms?

Edit: I've deleted my previous answer (which basically said "works fine on my machine") and replaced it with the following On your custom UserControl set AutoScaleMode = Inherit This should correct the excessive scaling of the user control.

Edit: I've deleted my previous answer (which basically said "works fine on my machine") and replaced it with the following. On your custom UserControl, set AutoScaleMode = Inherit. This should correct the excessive scaling of the user control.

It has to be a System.Windows.Forms. UserControl, not just a normal control. – Jules Apr 2 '10 at 14:53 I've amended my question to clarify – Jules Apr 2 '10 at 14:56 Damn I hadn't seen your edit, it appears to work!

I'd originally hard coded AutoScaleMode = Font into the usercontrol because that's what the designer does and I was having probs before. I'll do some further testing and hope my previous problem doesn't occur. Any idea why it works?

– Jules Apr 2 '10 at 18:37 Well, I knew there was a reason I'd changed it to an explicit AutoScaleMode = Font. If it's set at inherit, it works for the case I describe in the OP, except when the container form is initially set to a non-default font. My solution is to set the AutoScaleMode to Font, then after the control is added to a form, I set it to Inherit.It will then scale correctly if the font is changed at run-time.

– Jules Apr 2 '10 at 18:51.

No repro, it scales perfectly. It will not scale properly if you've set the Font property of the UserControl and it doesn't match the font size of the form. The Font property is an "ambient" property, like ForeColor and BackColor.As long as you leave it to the default setting (not bold in the Properties window) then it will use the Font of the parent.

When every control uses the same font size, they'll all scale proportionally. To fix, select the text of the Font property in the Properties window, press Backspace to erase it and press Enter.It resets back to the default. Fix your code like this: this.SuspendLayout(); UserControl1 uc = new UserControl1(); this.Controls.

Add(uc); this. ResumeLayout(false).

– Refracted Paladin Apr 2 '10 at 15:29 Yes, that's how ambient properties work. – Hans Passant Apr 2 '10 at 15:33 Thank you, I have, somehow, never heard that before. – Refracted Paladin Apr 2 '10 at 15:35 No it's not that.

I haven't touched the properties of the usercontrol. All I did was create it, colour the background, so I could see it, and add a few buttons. The scaling is happening because the controls In the usercontrol scale correctly.It's The usercontrol itself that is growing too large.

Perhaps it's something to do with VB? – Jules Apr 2 '10 at 16:27 The best way to see it is to put a button in the bottom-right hand corner of the usercontrol (leave the anchor at default). After increasing the font size, the gap between to button and the edge of the usercontrol is far too big.

– Jules Apr 2 '10 at 16:31.

Edit: I've deleted my previous answer (which basically said "works fine on my machine") and replaced it with the following.

No repro, it scales perfectly. It will not scale properly if you've set the Font property of the UserControl and it doesn't match the font size of the form.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions