Reputation: 121
I have a Windows Forms Application in .NET 5 with Application Framework activated and the startup object set to (my) MainForm
.
Using "View Application Events" in the application's properties, I auto-generated the ApplicationEvents.vb
file and with the given controls auto-generated a method to do something on Startup (as I understand before even the MainForm
loads) - but nothing in this method gets run, not even breakpoints are triggered.
I would assume an auto-generated sub in an auto-generated file designed for this should work and every other event handling sub does, just not Startup's.
This is my ApplicationEvents.vb
(without the auto-generated comment):
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
Partial Friend Class MyApplication
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
Debug.Print("Test")
MsgBox("Test")
End Sub
End Class
End Namespace
I'm trying to enable high DPI scaling for my application.
For this I've tried using the app.manifest
file (opened by "View Windows Settings" in the application's properties), but no combination of tags I found in the docs worked (I'm running the required version of Windows 10 of cause).
The same for the app.config
file, but I expected this because it's a .NET Framework feature to use it for that.
So I landed on Application.SetHighDpiMode(HighDpiMode)
. This worked when put into the MainForm
's Load
event, but it only did what was intended when the form was already loaded and it was then put on a scaled up screen / the screen was scaled up while it was already loaded.
If it was started on an already scaled screen, it looked jumbled.
So I figured that enabling it only on the form loading is just a bit too late and it should be run asap, so I landed on Startup.
Upvotes: 1
Views: 771
Reputation: 121
The startup object has to be Sub Main
for the Startup event to work, not MainForm
(or any form at all).
(Thanks to @Hans Passant for the tip.)
If you want to change which one is the main form later on you have to do the following:
My Project
.Application.myapp
with any text editor.<MainForm>
tags to your (new) main forms name.ApplicationDesigner.vb
with any text editor.Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.YourProjectsName.YourMainFormsName
End Sub
This way you can keep the application framework and don't have to write your own Sub Main
.
Upvotes: 1