By now you will have noticed that the code behind the form contains a lot more
than just the button events we accessed. In fact it contains everything needed
to create what we created using the visual designer. We could have opened notepad,
and typed all of it in ourselves, then compiled it and it would have executed
just fine. In fact lets do just that but let’s not type it in. We can copy and
paste what we need. We don’t need some of the designer specific code created
by VS.Net so to be clear here’s what we’ll use:-
First off we need to create our references and declare the form Class
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Public Class frmMain
Inherits System.Windows.Forms.Form
This declares the form and specifies that it Inherits from the form namespace,
i.e. it is a form.
Next up we declare our controls outside of the following procedures
Friend WithEvents cbCancel As System.Windows.Forms.Button
Friend WithEvents cbAccept As System.Windows.Forms.Button
Friend WithEvents txtEnteredText As System.Windows.Forms.TextBox
Friend WithEvents lblEnterText As System.Windows.Forms.Label
The Friend keyword allows us access to them from the second instance of the form
we create. You can use Private if you don’t want to directly access them from
inherited forms.
Shared Sub Main()
System.Windows.Forms.Application.Run(New frmMain())
End Sub
This is the Main procedure that the compiler looks for in any project.It’s the
first thing that runs when you launch the exe.
Comments