Object Oriented Program Model in vb.net

Ratings:
(4)
Views:203
Banner-Img
  • Share this blog:

 

Object-Oriented Program Model:

object oriented program model  

  • Suppose an institute approached you to develop software. Let us see that many institutes will approach you to develop a website for them. You need not develop a specific project for every single rather than to develop a single project & edit.
  • In the above design, we take an institute class and it contains courses offered since we know a variety of courses and address is varied 1m to other institutes.
  • The client is peers discount by default is R.S of if joining by the group may be discount consists.  

Event handling in .NET:  

Event:

These are the actions that are allowed on control or an object.  

For Ex: Click, Mouse Move, etc.  

Event handling:

These are the methods that provide the functionality or the task to be executed whenever an event has been raised on a control. VB.Net supports two types of Event handlers

  • Static Event handlers
  • Dynamic Event handlers

Using console application for projecting a windows form

To use Windows Form, the “System.Windows.Forms.Form” class should be used.

Open console application

If we Write Imports System.Windows.Form //gives error

So go to project [menu] à add a reference

In add reference menu select .NET & select System.Windows.Forms & press OK

Hence error is removed automatically

‘‘Demo on using a console application to project win form

Imports System.Windows.Forms

Module Winform’’ Demo

Class FClass

Inherits Form

End Class

Sub main ()

Dim fc as New FClass

fc.Text = “VB 270 WinForm ‘‘Demo”

fc.showDialog ()

End sub

End Module

  • Execute then we get a WinForm

Inclined to build a profession as VB.Net Developer? Then here is the blog post on, explore VB.Net Training

Static Event handlers:

Whenever an event handler is defined for the objects or controls created at the design time then it is said to be a Static Event Handler.  

Note:

To bind a static Event Handler for, a control or an object then it is mandatory to create the objects using the “WithEvents” modifier.    

Syntax to define a Static Event Handler:

Private sub ControlName_EventName (By Val sender as Object, By Val e as xEveneArgs) handles ControlName.EventName

Statement(s)

- - - - - - -

End sub

Take a New Module

‘Demo on Static Event handling . . . .

Imports System.Windows.Forms

Module Static Event Handling Demo

Class FClass

Inherits Form

WithEvents t as New TextBox

Sub new ()

t.Multitime = true

t.ScrollBars = ScrollBars.Vertical

t.Dock = DockStyle.Fill

Me.Text = “StaticEventHandlingdemo”

Me.Controls.Add(t)

End sub

Private sub t.Keypress (By Val sender As Object, By Val e as KeyPressEventArgs)

Handles t.KeyPress

e.Handled = True ‘Nullify the KeyPress (Don’t take p/p of user)

t.Text$ = “East or West .Net is best

So eat.Net, Drink.Net, sleep.Net, .Net simply rockzzzz”

End sub

End class

Sub main ()

Dim fc as New FClass

fc.ShowDialog ()

End sub

End Module  

Dynamic Event Handlers:

Whenever an Event Handlers are being defined for the controls that are created at the runtime then it is said to be Dynamic Event Handling.  

Syntax to add a Dynamic Event Handler:

AddHandler, ControlName.EventName, Address of Method Name  

Note:

  • Any modifiers can be used for defining the objects.
  • Dynamic Event Handlers can be removed at run time but Static Event Handlers can’t be removed.
  • To remove a Dynamic Event Handler

 Syntax:

RemoveHandler, ControlName.EventName, Address of MethodName

Take a New Module

‘Demo on Dynamic Event handling . . . .

Imports System.Windows.Forms

Module DynamicEventHandler

Class FClass

Inherits Form

Sub new ()

Dim f/p as new FlowLayoutPanel

For I as Integer = 1 to 5

Dim b as New button

b.Text = i

AddHandler b.click, address of b_click

fip.Controls.Add(b)

Next

Me.Text = “DynamicEventHandlingDemo”

Me.Control.Add (fip)

End sub

Private sub b_click (By Val sender as Object, By Val e as EventArgs)

Dim b as a new button

B = (Type (sender, Button)

MessageBox.Show (“You have clicked” & b.Text, Me.Text)

End sub

End class

Sub main ()

Dim fc as New FClass

fc.ShowDialog ()

End sub

End Module

Execute  

Observation

  Dynamic event handlers  

This is nothing but the object from which the event is raised.

Ex: 1, 2, 3, 4, 5

The sender must object so we must convert

We use C Type

C Type (Sender, Button)

It must be assign to b which means

  • Sender in the event handler maintains the object which has raised the event.

   

For an in-depth knowledge, click on below

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox