Pemprograman VB Dot Net Present by: Johanes Fernandes Andry Session 5 : Desain User Interface & Inheritance SEKOLAH TINGGI MANAJEMEN INFORMATIKA & KOMPUTER Widuri
Prinsip Desain User Interface Komposisi : tata letak/layout tampilan aplikasi. Prinsip- prinsip dalam pengaturan komposisi ini adalah : kesederhanaan posisi kontrol konsistensi white-spice color font menu/toolbar
Interfaces To define an interface, use the Interface statement: Public Interface ISomeInterface Sub SomeSub( ) Function SomeFunction( ) As Integer Property SomeProperty( ) As String Event SomeEvent( _ ByVal sender As Object, _ ByVal e As SomeEventArgs _ ) End Interface
example Public Class SomeClass ' This indicates that the class implements the methods, ' properties, and events of the ISomeInterface interface. Implements ISomeInterface ' This method implements the SomeSub method of the ' ISomeInterface interface. Private Sub SomeSub( ) Implements ISomeInterface.SomeSub ' ... End Sub ' This method implements the SomeFunction method of the Private Function SomeFunction( ) As Integer _ Implements ISomeInterface.SomeFunction End Function ' This property implements the SomeProperty property of the Private Property SomeProperty( ) As String _ Implements ISomeInterface.SomeProperty Get End Get Set End Set End Property ' This event implements the SomeEvent event of the Private Event SomeEvent( _ ByVal sender As Object, _ ByVal e As SomeEventArgs _ ) Implements ISomeInterface.SomeEvent End Class
Form Form merupakan bagian dari kontrol seperti textbox dan label. Memanggil form : Form Modal : form yang harus ditutup terlebih dahulu sebelum user dapat mengakses form lainnya. NamaForm.ShowDialog() Form modeless : form yang tidak harus ditutup terlebih dahulu ketika user mengakses form lain. NamaForm.Show()
The Windows Forms Designer-generated code for a blank Form Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New( ) MyBase.New( ) 'This call is required by the Windows Form Designer. InitializeComponent( ) 'Add any initialization after the InitializeComponent( ) call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose( ) End If MyBase.Dispose(disposing) 'Required by the Windows Form Designer Private components As System.ComponentModel.Container 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough( )> Private Sub components = New System.ComponentModel.Container( ) Me.Text = "Form1" #End Region End Class
Hello, Windows!, as created by the Windows Forms Designer
Parent and Child Forms The main form is called the MDI parent, and the child forms are called the MDI children. The Form class has two properties that control whether a given form is an MDI parent, MDI child, or neither. The MdiParent property (which is of type Form) controls whether a form behaves as an MDI child. Setting the MdiParent property of a form to reference the application's MDI parent form makes the form an MDI child form.
Example: A minimal MDI application Imports System Imports System.Windows.Forms Public Module AppModule Public Sub Main( ) Application.Run(New MainForm( )) End Sub End Module Public Class MainForm Inherits Form Public Sub New( ) ' Set the main window caption. Text = "My MDI Application" ' Set this to be an MDI parent form. IsMdiContainer = True ' Create a child form. Dim myChild As New DocumentForm("My Document", Me) myChild.Show End Class Public Class DocumentForm Public Sub New(ByVal name As String, ByVal parent As Form) ' Set the document window caption. Text = name ' Set this to be an MDI child form. MdiParent = parent
Figure: A minimal MDI application
Menu & Toolbar ContextMenuStrip Menampilkan menu popup ketika pengguna mengklik mouse kanan pada suatu object MenuStrip Mewakili menu utama, submenu dan item menu form StatusStrip Terletak di bawah form sebagai status ToolStrip Menampilkan kumpulan tombol, drop-down dan tool lainnya agar pengguna dapat mengontrol aplikasi ToolStripContainer Kontainer yang mengatur kontrol ToolStrip untuk dock(menempel) pada tepi form
Inheritance Inheritance is one way to reuse and extend previously written code. A program's design often requires several classes as variations of a common theme. Consider a drawing program that deals with many shapes. Such a program would probably define a class for each kind of shape. However, there would be much in common among such classes, including many of their fields, methods, and events. Inheritance allows these common features to be extracted into a base class from which the various specific shape classes are derived.
Inheritance Selain konsep enkapsulasi, keuntungan lain dari object-oriented programming adalah kode program yang bersifat reusable. Sehingga waktu pembuatan program dapat dikurangi, serta dapat menghindari berbagai kesalahan yang tidak perlu. Visual Basic 2008 memperkenalkan konsep reusable ini dalam sebuah proses yang disebut inheritance (pewarisan)
Inheritance Dengan pewarisan, kita dapat membuat Class baru yang mewarisi sifat dari Class lainnya. Class baru tersebut lebih spesifik dari Class yang diwarisinya. Class Baru tersebut disebut sebagai turunan (child) dari Class induk yang diwarisinya (parent). Child Class mewarisi seluruh Field, Properti, Metode, dan Event yang dimiliki oleh Parent Class. Child Class dapat mengakses Field, Properti, Metode, dan Event yang dimiliki oleh parent-nya, asalkan tidak bersifat Private. Parent Class disebut juga sebagai Base Class, sedangkan Child Class disebut juga sebagai SubClass.
Latihan Session 5
Klik tombol bilangan ajaib 1
Hasil Tombol Bilangan Ajaib 1
Klik tombol bilangan ajaib 2
Hasil Tombol Bilangan Ajaib 2