I have a form which have so many controls in an old winForms App
the client said he's using low screen resolution to easily manage this form
and now he want the controls and there font size to be big regardless of the screen resolution
if it's not an easy process is there any thing i can start with ?
Put this in the form's OnLoad override or Load event handler:
this.Font = new Font(this.Font.FontFamily, 1.25f * this.Font.Size);
Which takes advantage of the built-in autoscaling as configured by the AutoScaleMode property. Whether that will keep the layout intact is a unguessable, you'll have to try.
Your customer can do this too by increasing the video adapter's DPI setting. On Vista and up, going past 125% (120 dpi) triggers compatible DPI scaling. Which makes the OS lie about the DPI setting and produces a larger window through bitmap scaling. Makes it fuzzy but big enough to be usable.
You can change the style for each of the controls or you can create a style class and change your controls to consume it as shown in the following link: http://www.codeproject.com/KB/miscctrl/WinFormStyleSheet.aspx
Most winforms controls that display text have a FontHeight property which you can modify in order to set the permanent font height for that particular element. This is the most flexible solution where you can control which elements get the larger font treatment.
Related
I know this is an "already heard" problem: I have searched a lot but I did not find anything that cleared my mind.
I am developing a c# application with a GUI containing some controls like buttons (made with images) and text.
I developed it setting the main form size to 800x600 but now I need the application to work also on a 1920x1080 screen.
Two problems:
If I position a button near the top-right corner of the main form and set AnchorStyles to Top-Right, when I switch to the big screen, the button is (in proportion) much more close to top-left corner than in the little screen (because the anchor keeps the distance from the border). Is there a way to set a proportional distance from the border?
How can I scale the dimensions of the controls proportionally to the screen size? Shall I use AutoScaleMode like suggested here?
There is a way to add a capability to a form at design time - the ToolTip control does it, that makes properties available to every control on a form. These are called "Extender Providers"
http://msdn.microsoft.com/en-us/library/ms171836
You would want to look at the controls, and cache their sizes and fonts at design time, and the size of the form.
The provider would hang off the form.SizeChanged event at run time. When the size changes, you use the new and original (design time) sizes of the form to calculate and X and Y ratio. You then go through each control and use it's design time size and the ratios to determine its new size and font size. This can get flaky if you allow the user to select sizes that are not the same aspect ratio as your original.
Anyway, that is how it was done in Delphi, and everyone knows if you can do it in Delphi, you can do it in C# :)
I have a WinForms Application that was designed to support Full HD resolutions (so 1920x1080). Now this App is also supposed to run on a lower resolution: 1600x900.
Is there a way to let the application auto scale itself to fit the lower resolution? Like you would just downscale an image, basically resizing and relocating each control.
My current forms and panels have set their size to 1900x1080, so they just extend out of the screen on the lower resolution.
I have played around with AutoScaleModes and AutoSize, but the best I could get were Scrollbars so that you at least navigate through the forms. Is such a thing as downscaling an application even possible (retaining dimensions/ relative sizes and positions of the controls)?
Thanks in advance for any inputs on this!
If your main form starts in a maximized mode, it will adjust its size automagically.
But (and this is a huge "but" according to your question): the inner controls won't be scaled as you would see on a smartphone. WinForm is not "vector based" as WPF. If you have a fully loaded form in 1920x1080, when the main form is sized down, the controls won't fit and you will get scrollbars.
So the answer is: No.
The solution is available.
Form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
and
Make all control autosize = false.
make a suitable size of your wish.
The property you are looking for is called Dock, it's a property of the controls.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock(v=vs.110).aspx
This basically tells the control how to fill the available space.
Creating a resolution independent application is not a simple logic. Everything in the window should be resize as per the selected resolution. Not only controls' size you have to change the font size also as per the changes. Here is the example how to create a resolution independent form using C# code. Another way is use DevExpress Tool. This tool provides Layout Countrol Container. You can place each control in separate layout item and assign the minimum and maximum size of control.
Whenever I try to increase the form width in the properties box of VS 2008 it just resets my change back to 1300. It lets me lower the width, but not increase over 1300. How can I fix this? I have a datagrid in the form which has a width over 1300.
Windows in Windows cannot be larger than your screen resolution.
In code (eg, in the form's constructor), you can set any width you want, and it will be restricted by the end-user's screen resolution at runtime.
Your form should not need to be so big; consider redesigning your UI and/or using scrollbars.
you should check the Form.MaximumSize.Width property
Form.MaximumSize Property
so if you need to increase one of the two or both make sure that MaximumSize is also updated to your new values.
Edit: SLaks is correct that you cannot have the form bigger than the monitor anyway...
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.
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.
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.
I have a custom control built of other controls that is being loaded in two different places. On one it appears the way it does in the designer, as expected, on the other it is being resized smaller without being instructed to do so. Even when I explicitly adjust the size in code the control appears to get bigger, but the controls within are still smaller than they should be. What could causing this to happen?
Any differences in the font size between the custom controls' containers (form, panel, etc.)?
See if setting your control's AutoScaleMode to Dpi helps.