Rojo
Rojo

Reputation: 276

.net winforms custom control with wrong sizes in designer

In my solution, I have a project in which I'm creating custom controls. When I build that project, I can insert the custom control in another project through the designer. All works well

With one of those controls however, and one of the forms, I'm having trouble. It's supposed to be a control of fixed size, with a listbox, a button, a groupbox and little else. But when I drag it from the designer, into this particular form, the listbox and button sizes are all wrong, way bigger than the original. This doesn't happen with other controls nor with other form. The properties I see in the properties window for all the forms (except for Text, Font, Name...) are the same.

I'd appreciate your ideas and guidance as to how to look for what's going on. I'm quite new with VS and .NET

Thanks

Upvotes: 0

Views: 1274

Answers (1)

Hans Passant
Hans Passant

Reputation: 941317

This will happen when that control was designed on a machine that had a different video adapter DPI (dots per inch) setting. When you use it on yours, the control automatically rescales itself to accommodate your machine's DPI setting. So that it appears just as large as it did on the original machine. In inches, not pixels.

This is normally highly desired, you don't want to mess with the control's AutoScaleMode property. Because if you do, it will misbehave on the user's machine when it has a different DPI setting. Fix your problem by editing the control's Designer.cs file. Look for code at the bottom of the InitializeComponent() method that assigns the AutoScaleDimensions property and make it the same as a control created on your machine. You may then also need to tweak font sizes.

Upvotes: 1

Related Questions