I built a windows application in C# that is very size specific. I hard coded the size of the form so that it could not be resized. The problem is when someone changes there windows settings to font size for example (125% or 150%) my application breaks and buttons get moved over, and things fall off of screen. The entire application is a mess.
Is there a way in C# to disable the custom font effects of windows and use the pre-set font I told it to use in my form. I want all windows custom features to be turned to default on my application.
Is this possible at all, like import a DLL and call a function or change my program.cs some how.
Don't do that. Write your application so it adapts to the user's selected font size.
Related
I'm having a problem that when i debug my application it doesn't match the size i've set in the designer. i've tried to set form minimum size to the desirable values.
The form is built up with a splitpanel, with a panel docked as fill on each side.
The labels have default anchors. Textboxes have anchors left,top,right.
Buttons have anchors left, top.
if i drag the bottom down during runtime i get the size/design i want, but why doesn't it start like that and how can i fix it?
Looks like you're working on quite a high resolution screen. Windows Forms isn't very good with scaling the content and has all kinds of quirks that you need to be aware of. I would move to WPF if possible, but if you really need to continue using Windows Forms, here's what you should do.
Use AutoScaleMode.Dpi on your main form. It'll scale and relocate the controls to match your design when the DPI of the monitor is higher than the default 96 (100%). You could also try AutoScaleMode.Font but it might not work well if you use fonts other than the default (Tahoma 8,25 pt or something like that).
Use TableLayoutPanel or FlowLayoutPanel to make positioning controls easier. FlowLayoutPanel dynamically lays down your controls horizontally or vertically. If you're familiar with WPF or Windows Phone development, it's basically a StackPanel control.
Make sure your screen DPI is 96 (100%) and keep it the same throughout the development. You'll still have to make sure to test the application on other DPI's so that users with different settings will be able to use your application.
Here's more information about DPI scaling:
How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?
How to control the font DPI in .NET WinForms app
Creating a DPI-Aware Application
Edit: Visual Studio's Windows Forms designer shows the form using a different theme than your Windows version so that's one reason why your form looks different in runtime. In runtime the form uses the theme of the operating system currently running the application.
i'm developing c# winform application, and having some sizing issues.
working env. :
developing on macbook, using vmware running windows 7, with visual studio.
also using infragistics winform controls.
the problem is that every time i'm opening the project, the size of the main form is changing, also the size of several controls in it is being changed.
so, i need to resize everything manually, before publishing the project.
this is very annoying, and i can't figure out what is causing this.
did someone here having the same issue, is there anything i can do to stop this?
thanks.
I have seen similar issues when windows default font size is changed in Control Panel Display settings. It probably has something to do with the Form's AutoScaleMode.
Is it changing by a lot or a little? Is it one pixel or is it a huge difference?
There were some known issues with UltraToolbarsManager in certain styles where opening the form in the designer changed the size of the form each time, but it was a very small change and it was consistent - meaning that the form would always get a little bigger or a little smaller each time.
These issues are all fixed in the latest version as far as I know.
What I want to achieve is the following:
Lets say we have a basic program written in C#, whatever it does, that has some controls, shows some self made dialogs, etc and has plugin support. You can load plugins dynamically during run time and unload them again.
How could i write a plugin that lets you pick a font and then sets that picked font as the default font for the form that loaded the plugin, all of it`s child controls (which is easy), and all dialogs it shows after the font was changed?
Ive been googling for hours and most i found was something like this:
Form2 win = new Form2();
win.Font = this.Font;
win.ShowDialog(this);
while this works of course it means touching the source code and changing it everywhere a window is shown. And a plugin obviously cant re-compile a program while it runs or find all the lines of codes where it would need to make changes or do all of the above and restart the program without losing any data.
The goal is that someone who has little knowledge of the main program can still write a Plugin that lets them choose a desired font for the program. That someone would only know how to program the plugin and how to load/unload it.
Searched material includes:
Changing default font in Windows messes up my Win Forms buttons
http://msdn.microsoft.com/de-de/library/system.drawing.systemfonts.defaultfont%28v=vs.110%29.aspx
How to use system font settings for a Windows C# app
System.Drawing.Font can be instantiated with a string indicating the FontName.
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style);
how do i make sure that the application iam developing will look the same on other windows-systems?
iam developing now on a windows7, with .net 3.5 framework .. (VS 2008)
as an example, i have a toolbar, that i changed its rendermode to system, it looks ok on my windows7, but when i run the application on windows xp, it is different, even the onmouseover backcolor is different. ..
is there a way to make the application looks like on every windows system (talking abt xp, vista and windows 7 only), lets say like exporting the settings of all the controls with the application !? or any trick to make sure it will be always the same ?
thankss in advance
Unless you render the window yourself you're going to always have slight differences between OS'es, they all have different ways of rendering your primitive controls like text boxes, panels, etc.
Also under windows the background color of a window/control is actually (by default) tied into the theme set in windows.
So allowing people to use their own themes is a plus. You really shouldn't force a style on people unless you're theming your own application.
You would have to you get a grab on all of the colours, fonts, transperancy, etc. and use them to override every controls' Paint event/method so that they may use your values.
The only way I see fit would be by writing yourself custom controls while handling these controls appearance throught the Paint() method so that the control may use what you give it. The pain!...
As SLaks commented, you shouldn't care about such details and let the defaut user preferences take over on the native OS, because some surprises may be encountered over time as if Windows doesn't find the font, for instance, it will replace it with its default, which could lead to horrible results. That is just one example. Need others?
We have a collection of C# (.NET 2.0) applications that have custom dialog windows. When the user changes the default font size and resolution etc in Windows the edges of the form lose controls (they get pushed off the visible portion of the form) typically dropping off buttons from the bottom. This is problematic for us and will cause issues across other applications using the standard look-and-feel framework we are creating around these applications.
How would you make your entire application independent from windows font changes? How would you integrate this into multiple solutions?
Or better still how can one adapt the entire application to be able to adjust itself with the Windows appearance changes?
WinForms have the AutoScaleMode property, which can be set to either Font, DPI, Inherit, or None. The default is "Font" which, in my experience, doesn't always scale things right. You might try one of the other options (maybe "None" if you don't want your form to scale at all?)
As for making the entire application able to adjust itself, look into the "Inherit" option (you still need to set something other than "Inherit" on the parent or startup form of your application, though).
You could handle the SystemEvents.UserPreferenceChanged event in the Microsoft.Win32 namespace. The UserPreferenceChangedEventArgs parameter will have a Category of UserPreferenceCategory.Window when the system font changes. I think you'll then have to trigger a manual window layout and redraw in response to this event.