You can create a simple form by writing the code in an editor, for instance Notepad. Let's create a VB.NET program. SampleForm.vb, to learn how to create a form using Notepad editor.
Imports System
Class MyForm
Inherits System.Windows.Forms.Form
Friend WithEvents Button1 As System.Windows.Forms.Button
Sub New()
MyBase.New()
InitializeComponent()
End Sub
Private Sub InitializeComponent()
Button1 = New System.Windows.Forms.Button
Button1.Location = New System.Drawing.Point(100, 100)
Button1.Name = "Button1"
Button1.Size = New System.Drawing.Size(75, 23)
Button1.TabIndex = 0
Button1.Text = "Click Me"
Button1.UseVisualStyleBackColor = True
Me.Text="Sample Form"
Me.ClientSize = New System.Drawing.Size(250, 250)
Me.Controls.Add(Me.Button1) 'Add Button to form
Me.Name = "MyForm"
End Sub
'Click Event handler for Button1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("You clicked Me")
End Sub
End Class
Module Module1
WithEvents frm1 As MyForm
Sub Main()
frm1 = New MyForm()
frm1.Show()
Windows.Forms.Application.Run(frm1)
Console.Read()
End Sub
End Module
In above code, a class is created that inherits from the Forms class. which belongs to the System.Windows.Forms namespace. The System.Windows.Forms namespace contains all the classes related to GUI based form development. Then, a control is added to the form, for instance button, and event handing code is added to deal with this control.
0 comments:
Post a Comment