Overrides Overridable methods : Overridable « Class Module « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Class Module » Overridable 
6.42.1.Overrides Overridable methods
Option Strict On
 Imports System
 Public Class Control

     Public Sub New(ByVal top As Integer, ByVal left As Integer)
         Me.top = top
         Me.left = left
     End Sub

     Public Overridable Sub DrawControl( )
         Console.WriteLine("Control: drawing Control at {0}, {1}", top, left)
     End Sub

     Protected top As Integer
     Protected left As Integer
 End Class

 Public Class Label
     Inherits Control

     Public Sub New(ByVal top As Integer, ByVal left As Integer, ByVal n As String)
         MyBase.New(top, left)

         text = n
     End Sub 

     Public Overrides Sub DrawControl( )
         MyBase.DrawControl( ) 
         Console.WriteLine("Writing string to the listbox: {0}", text)
     End Sub 

     Private text As String 
 End Class 

 Public Class Button
     Inherits Control

     Public Sub New(ByVal top As Integer, ByVal left As Integer)
         MyBase.New(top, left)
     End Sub 'New

     Public Overrides Sub DrawControl( )
         Console.WriteLine("Drawing a button at {0}, {1}" + ControlChars.Lf, top, Left)
     End Sub 
 End Class 

 Public Class Tester

     Shared Sub Main( )
         Dim win As New Control(12)
         Dim lb As New Label(34"test")
         Dim As New Button(56)
         win.DrawControl( )
         lb.DrawControl( )
         b.DrawControl( )
         
         Dim winArray(3As Control
         winArray(0= New Control(12)
         winArray(1= New Label(34"AAA")
         winArray(2= New Button(56)

         Dim As Integer
         For i = To 2
             winArray(i).DrawControl( )
         Next i
     End Sub
 End Class
Control: drawing Control at 1, 2
Control: drawing Control at 3, 4
Writing string to the listbox: test
Drawing a button at 5, 6

Control: drawing Control at 1, 2
Control: drawing Control at 3, 4
Writing string to the listbox: AAA
Drawing a button at 5, 6
6.42.Overridable
6.42.1.Overrides Overridable methods
6.42.2.Overrides and Shadows methods from base class
6.42.3.ToString method overrides
6.42.4.Derived Class and Overrides
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.