New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DPI scaling support for .NET Framework|Core WinForms apps #563
Comments
Hi @citizen3942, |
WinForms traditionally has had terrible support for DPI scaling which has caused many of these types of problems in the past. @citizen3942 are you using a .NET Core WinForms application? I wonder if .NET Core WinForms has better support for DPI scaling, which may mean this behavior/bug is new and different depending on which platform is being used. Present State of DPI Scaling in FormsPlotDPI scaling factor is defined here. It's initialized to 1 and never assigned to. Perhaps this should be detected and assigned to in the control constructor?
Regarding switching monitors, I haven't looked into this yet, but I wonder if there's an event that fires when DPI scale changes? If so, we could use that event to update the |
I was right! This is a difference between .NET Framework and .NET Core WinForms apps. This is using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp6
{
static class Program
{
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware); // <-- THIS IS NEW
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
} If you comment-out the line to make the WinForms application DPI-aware, ScottPlot's mouse tracking works as expected. I'll see what I can do to improve WinForms DPI scaling support in .NET Core applications though... |
improves support for .NET Core WinForms apps (.NET Framework WinForms does not support DPI scaling) #563
@citizen3942 This issue just affected .NET Core WinForms apps, |
Perhaps line 250 can be moved after line 17. I still want to believe that those functions that I pointed out in my first posts should have this dpiScale division for XY Locations. |
Good suggestion! It also doesn't need a default value anymore.
Dang, I messed-up here. I thought this problem was fully resolved by 3530434 but I overlooked the fact that in my |
This is the default DPI mode for new .NET Core WinForms apps #563
This issue is thornier than I thought. DPI scaling support for draggables is currently broken in the WPF control too. The most elegant fix (always handling scaling at the control level) is one that breaks the highlightable scatter plot demo... but that breaking change is probably the least impactful, since it's confined to a single plottable, and the best solution is to make this change and to improve the demo. |
DPI state is no longer stored in the plot settings module, but instead handled at the control level. This change fixes draggables which were previously broken. WPF users wanting to use ScatterPlotHighlight must get coordinates using wpfPlot1.GetMouseCoordinates() as seen in the demo application.
I think it's fixed now, and interestingly the fix was achieved only by deleting code... 319f94d I just uploaded version 4.0.42 to NuGet (it might take a couple minutes to show up) but @citizen3942 I'd appreciate your assessment as to whether it works as expected in your hands! |
The V Line and H Line positioning are now correct in v4.0.42, with different DPI settings. PS! I downloaded 4.0.42, but the package version was still 4.0.41. |
This sounds like something we should fix! If there is a
I'm a little confused by this. Can you clarify what the issue is? Thanks for following up! |
I found a fix for this. I added private void InitializeScottPlot(bool applyDefaultStyle = true)
{
AutoScaleMode = AutoScaleMode.Inherit;
ContextMenuStrip = DefaultRightClickMenu();
pbPlot.MouseWheel -= PbPlot_MouseWheel; // unsubscribe previous handler
pbPlot.MouseWheel += PbPlot_MouseWheel;
... It will help to Inherit the scaling properties of the parent control(s), that are set to DpiAware. |
Hey @citizen3942 thanks for following up on this! Looks like a great solution. This might be a nice way to totally disable display scaling for ScottPlot controls (and delete a lot of that display scale checking code) 🤔 I'm a bit embarrassed how long it's taken me to get to this issue. I got really sucked in to #605 and am still working on that... I hope to get it merged soon so I can clear out these issues! |
I'm actually having a hard time recreating this issue. I tried:
I can't get it to display improperly 🤔 If you can help me recreate the issue I can work toward resolving it, but otherwise I suspect it's working pretty well as it is! Ironically all this will get thrown out the window as people slowly migrate to .NET Core with time 😆 |
Plot draggables are not DPI aware:
I have had a little problem with draggable lines on my 4K screen, with 144 DPI.
The cursor handle was offset to the left from the vertical draggable line exactly 1.5 times - the ratio of 144 and 96 DPI.
In terms of a fix:
There was a little start in the FormsPlot.cs, but was not enough to support draggables on higher DPI screens.
So I dug in to the code and here is my quick fix for this situation:
PS! Talking already about DPI awareness... There is also an issue when I try to drag the WinForms window from one screen to another (from 96 to 144 and visa-versa), the plot does not rescale to fit the bounds of the parent container. The resizing works once I maximize the window to full screen.
The text was updated successfully, but these errors were encountered: