VB.Net/GUI/Control Subclass
Версия от 16:40, 26 мая 2010; (обсуждение)
Sub class Button class to create a Clock button
Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1
Application.Run(form1)
End Sub
End Class
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
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"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.
Friend WithEvents TickButton1 As TickButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TickButton1 = New TickButton()
Me.SuspendLayout()
"
"TickButton1
"
Me.TickButton1.Location = New System.Drawing.Point(16, 120)
Me.TickButton1.Name = "TickButton1"
Me.TickButton1.Size = New System.Drawing.Size(216, 23)
Me.TickButton1.TabIndex = 4
Me.TickButton1.Text = "Design Mode"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(240, 189)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TickButton1})
Me.Name = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
End Class
Public Class TickButton
Inherits System.Windows.Forms.Button
#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
"UserControl 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
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"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.
Friend WithEvents ticker As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ruponents = New System.ruponentModel.Container()
Me.ticker = New System.Windows.Forms.Timer(Me.ruponents)
"
"ticker
"
End Sub
#End Region
Protected Overrides Sub InitLayout()
" are we in design mode?
If DesignMode = True Then
Text = "Design Mode"
Else
ticker.Enabled = True
End If
End Sub
Private Sub ticker_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ticker.Tick
" update the text...
Text = Now.ToString
End Sub
End Class
Subclass Form
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ruponentModel
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1
Application.Run(form1)
End Sub
End Class
Public Class Form1
Inherits Ancestor
#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
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"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 InitializeComponent()
Me.SuspendLayout()
"
"Descendent
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.ClientSize = New System.Drawing.Size(300, 266)
Me.HeaderText = "HeaderText"
Me.Name = "Descendent"
Me.ResumeLayout(False)
End Sub
#End Region
" Do NOT include the Handles keyword!
Protected Overrides Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show("derived")
End Sub
End Class
Public Class Ancestor
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
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"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.
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents lblHeader As System.Windows.Forms.Label
Friend WithEvents cmdNext As System.Windows.Forms.Button
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.lblHeader = New System.Windows.Forms.Label()
Me.cmdNext = New System.Windows.Forms.Button()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
"
"Panel1
"
Me.Panel1.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.Panel1.BackColor = System.Drawing.Color.White
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblHeader})
Me.Panel1.Location = New System.Drawing.Point(4, 4)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(292, 68)
Me.Panel1.TabIndex = 0
"
"lblHeader
"
Me.lblHeader.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.lblHeader.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblHeader.Location = New System.Drawing.Point(16, 16)
Me.lblHeader.Name = "lblHeader"
Me.lblHeader.Size = New System.Drawing.Size(262, 28)
Me.lblHeader.TabIndex = 0
Me.lblHeader.Text = "Header Text"
"
"cmdNext
"
Me.cmdNext.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
Me.cmdNext.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.cmdNext.Location = New System.Drawing.Point(232, 232)
Me.cmdNext.Name = "cmdNext"
Me.cmdNext.Size = New System.Drawing.Size(60, 28)
Me.cmdNext.TabIndex = 1
Me.cmdNext.Text = "Next"
"
"GroupBox1
"
Me.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.GroupBox1.Location = New System.Drawing.Point(8, 224)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(284, 4)
Me.GroupBox1.TabIndex = 2
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "GroupBox1"
"
"Ancestor
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.ClientSize = New System.Drawing.Size(300, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox1, Me.cmdNext, Me.Panel1})
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "Ancestor"
Me.Text = "Ancestor"
Me.Panel1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Protected Overridable Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
End Sub
Public Property HeaderText() As String
Get
Return lblHeader.Text
End Get
Set(ByVal Value As String)
lblHeader.Text = Value
End Set
End Property
End Class