What is the correct form declaration in VB.NET?

I just migrate the project from VB6 to VB.NET using the Microsoft Update Wizard.

One form has been automatically updated to

Friend Partial Class frmAudFeedSentenceEdit Inherits System.Windows.Forms.Form 

But when I add a new form to a new project in VB.NET, it is declared as

  Public Class frmAudFeedSentenceEdit 

(without Inherits System.Windows.Forms.Form).

Which one is correct, please?

+4
source share
1 answer

When you create a form using Visual Studio, it will put the form information in two separate files.

The part you see:

 Public Class frmAudFeedSentenceEdit 

This is just an ad in the main file where you will usually work.

However, a second file is created ( frmAudFeedSentenceEdit.Designer.vb ), which will have:

 <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class frmAudFeedSentenceEdit Inherits System.Windows.Forms.Form 

As you can see, this is still a Partial Class , but the Inherits is placed in the file created by the constructor for you.

You can see this if you look in the Class View window, go to your form and double-click InitializeComponent() (since this Sub is defined in the constructor file).

+4
source

Source: https://habr.com/ru/post/1440105/


All Articles