JayT
JayT

Reputation: 107

.NET Custom Control: Prevent font size change/ inherit font scale/size from parent

I have created some controls in C#, and am successfully using them. However, on user PC's with custom set (font) DPI to let's say 125 % or even 150 % -- My controls inherit the new scale, and do not display correctly.

I would like to know how to disable my control from inheriting this scale.

Upvotes: 0

Views: 5054

Answers (2)

Timothy Fries
Timothy Fries

Reputation: 2233

If you're building your own application, you can set the AutoScaleMode property of a Form to "None" to disable the automatic resizing of the Form's font based on the system DPI setting.

If you're simply building a control that others will integrate into their own forms, you'll want to override the Font property of the control and force it to your pre-determined hardcoded value.

Also note that, as others have said, you don't want to do this -- the user has adjusted their system DPI for a reason, and overriding their choice is likely only going to make your control unusable to them. If the problem is merely that your control isn't scaling correctly when the system DPI is changed, make use of Winform's AutoSize capabilities and use layout panels that will automatically adjust as the size of things change, such as TableLayoutPanel (with AutoSize set appropriately on rows and columns) or FlowLayoutPanel.

Upvotes: 3

Thundersquirrel
Thundersquirrel

Reputation: 39

I know this is not the answer you would be looking for. But consider why people have their system set the way it is. it may be a vision problem or just their perference. Yes, handling the scaling diplay can be a pain, but that is better then a user disregarding your product because they can't read/use it.

Upvotes: 3

Related Questions