Preventing windows resizing from enlarging PictureBoxes - c#

I have a simple splash screen Windows Form in my application which, in the Visual Studio designer, looks like THIS.
The logo and the progress ring are each inside a PictureBox.
However, when I try to render the application on a windows 10 PC with the text and app scaling set to higher than 100% (for example, a 1080p 15.6-inch laptop), the result kind of looks like THIS (Taken from a PC with 125% resizing).
Do you know of a way to prevent the PictureBoxes from scaling, or perhaps a way to make the form scale up to keep track with the PictureBoxes?
EDIT: Just to be clear, it's the images INSIDE the PictureBoxes that scale up, not the PictureBoxes themselves.

Setting myPictureBox.SizeMode to PictureBoxSizeMode.Zoom solved the issue (Thanks Adds.)

Related

Moving development from 100% Windows scaling to 150% chops WinForms window

I use C# Winforms in Visual Studio 2010. Since I've upgraded my laptop from the old 1366 x 768 resolution laptop to a new laptop with a 1920x1080 resolution, I noticed a problem when continuing development on the new laptop. I isolated the issue down to the new 150% Windows OS-wide scaling (Windows on the old laptop used 100% scaling). When I run the program, the right side of the window is strangely chopped off.
Here's the working version on the old laptop (1000 pixels wide, or 1500 pixels in 150% scaled Windows mode):
And here's the new version on the new laptop with the chopped window (1286 pixels wide, when it should be 1500 due to the 150% scaling).
Upon immediately loading the project into the new 150% scaled Windows setup and running the program, it appears to work fine, but as soon as you move one of the buttons so that VS updates the designer code (button 5 was moved as you can see), and then run, the window is chopped.
Even when manually going into the Form1.Designer.cs code, and adjusting the ClientSize to a stupid high horizontal value like ClientSize = new System.Drawing.Size(3000, 709); results in a window width that is limited to 1286 pixels at most. (Not so) coincidentally, 1286 is around 1920 / 1.5.
Basically, what the heck is going on? This appears like a bug with VS's scaling management. To be clear, the problem occurs when moving development from a 100% Windows scaled screen to a 150% Windows scaled screen, on any system. You don't need two laptops to reproduce the problem, it can all be reproduced on a single laptop (but make sure you log out and into Windows after switching from/to 100% or 150%).
Finally, to be clear, I know about setting the DPI-aware setting to true using an app.manifest file. Although this allows clearer text and solves the chopped window problem, I do NOT want to go this route due to inconsistent changes in my program's GUI such as overlapping controls and misplaced items on some setups.
I've found two half-solutions so far:
First is upgrading to Visual Studio 2017 (which allows you to force 100% scaling in VS Forms designer even in 150% Windows scaling)
Second is keeping with an earlier version of Visual Studio (including VS 2010), but making sure Windows is set to 100% scaling. If you've only just changed the scaling setting, make sure to log out and in of Windows to ensure the scaling is applied appropriately.
A relatively simple workaround is to create a Panel Control that is the size you desire for the window, send it to the first layer (right click the control in the designer> send to back). Then set the form to AutoResize to fit that control. (also set AutoSizeMode to GrowAndShrink in case the form appears larger than it should)
This works great if you need Fixed forms but for Resizable forms you might want some extra code that resizes this panel when the form's resize event happens.

UWP is not showing correct scale and resolution when run on local machine

I have build a UWP project in 12" tablet size (which I chose from options provided when I design the UI in designer)
However when I run the application, it is shown too big on my screen, my design could not shown completely on the screen.
For example, I have 2 buttons in my design form top to down, only the top one is shown but the below one is missing due to my screen is not big enough to show them. But my laptop screen is 15.6", and previously the program was run in another desktop with a 24" monitor and it shows correctly.
Is there anything I can do to change the resolution/scale of my application on the laptop screen? My laptop resolution is 1920x1080.
Thank you.
I think the resolution is 2160*1440 for 12" 150% scale, my laptop resolution is only 1920*1080, how do I change the resolution?
Windows automatically selects a scale factor for each display based on its DPI (dots-per-inch) and the viewing distance of the device. So that the scale factor is defined by the windows. Details please reference Effective pixels and scale factor.
Users can override the default value and by going to Settings >System> Display > Scale and layout settings page. You could change the scale to 100% for your laptop.

Winforms Scaling and Cutting Issue in Screens with Different Resolutions

I have a desktop app that is developer for Windows operating Environment.The App was developed on a 1,280x720 Monitor.It works very well on most systems with normal screen resolutions.Including 1080P and old 17 and 15 inch monitors.
The thing is when it comes to Laptops with 15" screen and 1080P resolution,the App shows up correctly at first but after using a control,the window gets smaller.The Text gets larger and some controls fall on top of others.
Another issue is that when the user has adjusted this size setting to High
The app window gets Cut and it does not show the complete content.The Application is not full screen.
One user was using a Windows Surface Pro and to get the Application Fit,the above setting was reduced.But this made the App too small,so the user ended up getting a refund.
I'm not targeting Tablet(Surface Pro) users.The intended audience is desktop Users.
What is the best way to tackle this issue keeping winforms GUI.
Please advice.
It seems you're looking for the AutoScaleMode property. This will allow your controls to change size according to the zoom level of your users' PCs (which you pictured above).
There is some really good advice in this answer to 'Creating a DPI aware application'. But basically:
Set the AutoScaleMode of your base control (the Form) to Font or Dpi
Remove as many custom font settings from your controls as possible (this will restore them to the default MS Sans Serif at ~8pts)
Develop the app at the standard zoom level and then test it on larger screens with higher zooms, see how it goes.
Hope this helps

Windows XP application (.NET/C#) resize problem

I have a Windows (XP/Vista/7) application implemented in C# using .NET 3.5 and I have a weird resize problems on a small number of Windows XP machines (I haven't been able to reproduce the problem myself).
The application uses a System.Windows.Forms.Form with a System.Windows.Forms.Panel which holds sub-views. Each sub-view is in itself a System.Windows.Forms.Form. During initialization each sub-view is added to the panel (panel.Controls.Add(sub-view)) and the controller selects sub-view by playing with the Hide and Show-methods of each sub-view.
Figure 1 shows how the application normally looks. The panel is the part with the lovely waterdrop-background-image.
But on some Windows XP machines the application looks like figure 2. The entire application has been resized (weird in itself since I have static Max/Min attributes) and the panel is bigger (and has dropped slightly). The background image repeats and any text on the panel is also resized.
Any ideas what this can be? Can it be a .NET-related problem? I do not have access to the problematic machines so all have to go on at the moment is some blurry screenshots.
Update
It is a DPI problem. Changing the DPI setting (on Windows XP) and the application will be resized (but on Vista/7 it stays correct). Thank you for the speedy response guys.
Isn't this a result of DPI settings which was one of the key things WPF tried to address with it's ability to auto-resize, move, wrap, etc?
There are some similar questions around that involve issues caused by changing DPI:
WPF DPI issues
C# Scaling UserControl content to match users Dpi/Font Size
How to prevent font resize when changing the DPI of the system
high DPI problems

Mimic/emulate a specific screen resolution for sizing WinForms?

I am currently developing a Winforms Application that will run on a very specific tablet PC.
My development environment uses dual-17" monitors which are far bigger than the tablet screen size of 10.4" (1024x768).
Due to the purchasing department at my company the delivery of the tablet will not be until well into the design cycle.
Is it possible to mimic the tablet size so that I can adjust my forms to match?
You have couple of options:
set one of your screens to the tablet resolution. You might need to move your taskbar to that screen to get the proper-sized workspace.
install Virtual PC and create a VM with the tablet resolution.
set your main form size explicitly to the tablet PC resolution. For best results size it to the proper workspace size, not the desktop size.
Note that your form will have to still be relatively flexible, since users might configure their taskbar to be at a different position, or different size, thus affecting the available workspace for your app.
The fact that you have 1024x768 on 10.4" means the pixels are denser than your typical PC monitor. That means that text 10 pixels high on your monitor might look fine, but 10 pixels high on the tablet PC may be tiny and almost unreadable (even without loss of resolution).
Unless you can find a monitor with similar pixel density, I don't think you can properly mimic it. Even if you can shrink the application to a 10.4" section of the monitor, now you're probably dealing with sub-pixel shading which will look blurrier than on the tablet PC.
The best you can probably do is setting one of your monitors to 1024x768 (without stretching to fill the screen!), or just set your app to that size and eyeball it to take into account that it will actually be smaller.
You could try hosting your main form inside a user control or another form limited to the relevant size. However, the form is then not a "top level" form, but fairly closely looks and behaves like one.
You can perform normal form actions (minimise / maximise / move / resize / etc) so you can get a feel for what it is like and a certain size.
However in this instance, its best to always design the UI for the minimum resolution you have to target, and have it scale upwards on larger monitors.
very easy - if you're concerned about size, or users have to use the touch screen, start your form out with 10pt+ font
very cool - design the form size as, oh, 950x650. Experiment with the anchor property of each control. Allows you to make basically totally resizable controls (if you get creative with the anchor on groupboxes/panels and the controls inside them).
then set your form to maximize itself on the tablet PC (or e.g., if screen size is <= 1280x1024 - the Anchor property has its limitations as to what size increase looks reasonable).

Categories

Resources