Trouble with Forms

Hello,

I'm about to start working my way through a two O'Reilly books; Learning Visual Basic .NET and Programming .NET Windows Applications. I was playing with the latter this afternoon using the new VB Express Beta 2. The following code I could not get to work and I think it is something to do with the difference between .NET 1 and 2. The book examples are in .NET 1.


Imports System.Windows.Forms

Namespace ProgrammingWinForms

   Public Class HelloWorld
       Inherits System.Windows.Forms.Form

       Public Sub New()
           Text = "Hello World"
       End Sub

       Shared Sub Main()
           Application.Run(New HelloWorld())
       End Sub
   End Class

End Namespace
 


When run, the form shown still has the title "Form1." If I add a title through the form designer it adds a new routine:


      Private Sub InitializeComponent()
           Me.SuspendLayout()
           '
           'HelloWorld
           '
           Me.ClientSize = New System.Drawing.Size(292, 266)
           Me.Name = "HelloWorld"
           Me.Text = "Test Title"
           Me.ResumeLayout(False)

       End Sub
 


Could someone explain why the code the editor adds works

Thanks for any help,




Answer this question

Trouble with Forms

  • AllenD

    Hi,

    the InitializeComponent() Method is used by the WinForms Designer and added him even to .net 1.0 projects :)

    Where is Text declared in your first Code-Sample

  • Caioshin

    Hi Ralph,

    Thanks for your reply. The code example I left was incorrect. Sorry about that.

    Slightly different question; is vbc.exe included in the VB Express / .NET 2 download I can't find it on my system and I can't see a way in the IDE to build just single *.vb files.

    Thanks for any help. Smile

  • hadstj

    Thanks a lot rgerbig and spotty, your help is much appreciated. I can start working my way through these bookbs now. No doubt there will be more questions along the way! :)   

  • Adeze

    I think you'll find that VBC.EXE is included with the framework.

    Check out the \windows\Microsoft.NET\Framework\ ....

  • Trouble with Forms