Winforms: Add MyType to VB WinForms template

Created on 12 Jul 2019  路  17Comments  路  Source: dotnet/winforms

This is needed in support of getting VB code that uses My.* working out of the box.

Sync with @KathleenDollard on the correct content, but I think we want the following:

<PropertyGroup>
  <MyType>Console</MyType>
</PropertyGroup>

Eventually we will want MyType=WindowsForms that you get in the classic VB WPF project, but Console is what works now.

Visual Basic enhancement

Most helpful comment

@paul1956 you can just link to this file directly, no need to download anything

All 17 comments

This will likely make 3.1, not 3.0. We will add it for sure when the support is available for WinForms apps.

I spoke with @KathleenDollard yesterday and agree we can get this into 3.0. Please submit the PR or give us the precise content that needs to be added when everything is ready

Not sure this is the correct issue but I have been struggling with not being able to access any Form without first assigning New FormX to a variable then using the variable then disposing of the variable. Today I found https://docs.microsoft.com/en-us/dotnet/visual-basic/developing-apps/customizing-extending-my/customizing-which-objects-are-available-in-my. and noticed My.Forms is missing in Core3.0 and in the article it explains why I need My.Forms to access forms directly. Without My.Forms most VB developers will struggle as I have. If MyForms is not going to be in 3.0, "What's New" will need to explain the workaround otherwise people will get errors (and informational messages) that don't make a lot of sense (especially to VB's target audience).

Also if you add

<PropertyGroup>
  <MyType>WindowsForms</MyType>
</PropertyGroup>

The Settings.Designer will fail to compile because My.Application.[SaveMySettingsOnExit and Shutdown] are missing.

Adding @cston

It is my understanding that there remains VB runtime implementation work for MyType=WindowsForms that will not be done by 3.0 RTM.

Please hold off on making this change, there may need to be some things reverted from 3.0 and deferred to 3.1 such that MyType=X would not work. This should be moved to 3.1 after all.

OK, we'll move this issue to 3.1 in that case.

Will this solve issues with "My.Settings"? Or have User Settings been deprecated in .NetCore for something else? If so, what is its suggested replacement?

@elachlan My.Settings basically works for creating, using and saving Settings what is broken is AutoSaving on exit which requires _MyType = "WindowsForms". Any you referring to something else?

@paul1956 Thanks for the response. I can see its now showing up. Do I have to add anything to the vbproj file to enable the settings designer in visual studio?

@elachlan the designer is not part of 3.0. There are multiple options but IMHO all are ugly. I have a branch in Git for Core 3.0 and Master is Framework, others have 2 projects in same solution a Framework and Core 3.0. Even with that I have a bunch of #IF statements. You also will not have the My.Forms collection which causes many issues preventing code from just working, also there is no Main. the code below or something like it is needed.

#If NETCOREAPP3_0 Then
    <STAThread> ' Possibly optional
    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        Dim f As New Form1()
        Application.Run(f)
        f.Dispose()
    End Sub
#End If

The default font changed between Framework and Core 3.0 (for the better) so many things don't align. There are multiple resources with detailed instructions on the various workarounds or just Gitter me directly. I have opened individual Issues on what I have uncovered but most are either As Designed or tagged to a future branch.

One for thing there is no MsgBox, if you need one search NuGet where I put something that gives basic functionality, and you will need to import VBMsgbox, but without WinForms support isn't perfect.

@paul1956 thanks for all the information. It has been super helpful.

@elachlan download winforms-designer.md from link below it goes into some detail on how to use the Windows Framework designer in a shared Code 3.0 project, then you just need to make the changes above.

@paul1956 you can just link to this file directly, no need to download anything

@KlausLoeffelmann and @KathleenDollard to update on VB.

We'll discuss this later this week. Probably 16.9, but need to catch up with regards to this on a couple of other things. Moving this to 6.0 for now.

This is done with recent template work (#3893). Closing this.

Was this page helpful?
0 / 5 - 0 ratings