forms appear poorly scaled at runtime - vb.net

I have created a form in visual studio (vb.net winforms) and it looks great in designer however at runtime it appears extremely out of scale (on my computer only) - my computer is using resolution of 3840x2160 with DPI scaling of 250% - this is obviously the problem how do I make my application deal with this better?
I have tried using Autoscalemode, autosize, and autosizemode with the form only appearing more broken than it currently does.
Here is the appearance in designer:
Here is the appearance at runtime on my computer:

Is your application DPI Aware? Read this article for more info: https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx
Basically you want to add this to your app.manifest inside the <asmv1:assembly> block:
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>

Make sure that you didn't change the default anchor property of the tools. Also make sure that you don't change location or size of the tools at runtime.

Related

Delphi IDE has no color control for Standard Components

My Alexandria Delphi IDE has lost its color control for Standard Components.
I cannot set the Font color at design time for components like TLabel, but it's correctly applied at run time.
Non-standard components i.e. JvLabel seem to work at design time and run time.
Parent Font is False.
Have I screwed a setting somewhere?
From my point of view this is a new bug in the Designer of Delphi 11.
In Delphi 10.4.2 the color display of TLabel.Font.Color still worked correctly in the Designer.
I recommend creating an RSP in Embarcadero's Quality Central for this bug.
Update 19-Jan-23:
This is an already known problem of Delphi 11.X.
You can uncheck "Tools->Options->User Interface->Form Designer->mimic the system style" option as a workaround.

VS 2022 Preview not showing the XAML designer

I've just installed VS 2022 preview to use Maui but there seems no way to see a designer view of the XAML, I want to drag and drop controls onto the page but all I get is an ancient looking XAML text view.
Visual Studio has removed the XAML designer. For now, there is no official plan to readd it.
But Visual Studio support Hot Reload to modify your apps managed source code while the application is running, without the need to manually pause or hit a breakpoint. You could preview the view at runtime when you change the UI. For more details, please check the blog. https://devblogs.microsoft.com/dotnet/introducing-net-hot-reload/
Like Cfun said, you could use live visual tree as well. It shows a tree view of the UI elements of your running Xamarin.Forms application. https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/live-visual-tree
For a WPF dotnet6 project, the XAML designer can be enabled here:
Don't know why it's disabled by default.

How to make WinForms application completely ignore any kind of DPI settings?

I have WinForms application written in VB .NET that "explodes" on non default DPI settings. This applications uses some ActiveX controls that just don't work with scaling.
I'm kindly asking you not to suggest me to rewrite it, move it to WPF and this kind of advices. I am fully aware that this application is bad, really bad. My job is just to make it "work".
Is there any way to make it so that application ignores completely any DPI setting? Any solution is good one as long as it works.
Right-click the executable -> Properties -> Compatibility -> Check "Disable display scaling on high DPI settings".
(Might be slighly different on Windows version other than 10.)
This did it for me for legacy applications that "explode".
Adding this to your manifest file should do the trick:
<asmv3:windowsSettings
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>false</dpiAware>
</asmv3:windowsSettings>
Try setting AutoScaleMode to None for automatic scaling. You probably also have to 'scale' the font. This can be done by adding the following before InitializeComponent
Font = new Font(Font.Name, Font.Size * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont);
I don't know how the hosted ActiveX control responds to these settings. Please let me know when you tried.

Inspecting XAML in Windows 8 Store Apps / VS2012

I'm looking for a way to inspect running XAML in a Windows 8 store app. Essentially, I want firebug / chrome inspector style functionality where I can look at the XAML source generated at runtime, to debug simple layout and style issues.
I've tried Snoop, Pistachio and WPF Inspector but none work for Windows Store apps. The only one I can find which seems to work for Store apps is XAML Spy, which is €90. I can't justify that cost.
Is there any other way to inspect running XAML?
WinRT XAML Toolkit now has an actual visual - visual tree debugger.
Get it from NuGet: nuget.org/packages/winrtxamltoolkit.Debugging then call WinRTXamlToolkit.Debugging.DC.ShowVisualTree() to display the debugger tool inside of your app. It's the third option so now you can use
the WinRTXAMLToolkit.Debugging.VisualTreeDebugger class - that enables you to debug the tree in your Visual Studio
XAML Spy - which is a great commercial visual tree debugger that runs in a separate window
and now this visual tree debugger in the WinRT XAML Toolkit that works inside of your app.
The VisualTreeDebugger class from WinRT XAML Toolkit is what you could use if you want a free tool. It doesn't do as much as XAML Spy, but you get what you pay for. I thought of adding more features to it like actual visualization of what you debug, but the work required would not justify the time investment + I didn't want to step on Koen Zwikstra's turf. I am sure he is doing a great job on that tool. Anyways - VisualTreeDebugger is enough for me, so maybe it would also be enough for you.
The way you can use it is add the class to your code, add a reference in your XAML like
xmlns:debug="WinRTXamlToolkit.Debugging"
then put a hook on a control where you would like to start debugging, like
debug:VisualTreeDebugger.BreakOnLoaded="True"
which will dump the core visual tree details as text in your debugger output window (Ctrl+W,O) and break in the code that dumped your tree where you can investigate the "path" variable, which contains the list of all visual tree elements from the debugged control to the root, so you can watch their values if what you need wasn't already dumped in the output window.
Other options include
debug:VisualTreeDebugger.BreakOnTap="True"
debug:VisualTreeDebugger.BreakOnLayoutUpdated="True"
debug:VisualTreeDebugger.BreakOnLoaded="True"
debug:VisualTreeDebugger.TraceOnTap="True"
debug:VisualTreeDebugger.TraceOnLayoutUpdated="True"
debug:VisualTreeDebugger.TraceOnLoaded="True"
Since it is source code and really a single simple class - you can easily add additional things to the code to do any custom debugging you need.
XAML Spy is what you need. You find it at http://xamlspy.com.
there is a new free tool called XAML Inspector. It's available through NuGet. Just search for "xamlinspector" or get if from the project page: www.xamlinspector.com
Greetings
Christian

Visual Studio 2012 XAML Designer Vertical Split Can't Be Set As Default?

Is there only Horizontal Split as default and not Vertical Split? Again or my eyes are going bad? It was an issue in VS2008 and VS2010 when it was per-file basis so nothing has changed?
Yep there is currently no way of defaulting to a vertical split for the XAML designer in VS2012.
Like you mentioned the only way at this point is doing it per-file basis as these settings are saved together in your .suo file.
This applies to VS08 and VS10 or VS12...
If you do want to let microsoft know that you would like this to be a feature you can send them a request here
Here is the original thread about this issue.
Its funny though that their HTML designer does allow defaulting to vertical split..