Как да се проектира (design) форма (form)
за апликация на Windows
Когато
създавате нов проект Windows Application, проектът започва с отделна, празна форма. Можете да добавяте контроли към формата, да
избирате свойствата им и т.н.
Показваме кода за форма, който изцяло се
подава от VB
.NET за нас. Формата има етикет lblMessage, текстова кутия txtValue и бутон btnOK, вижте листинг 1.
Listing
1Генерираният
за вас код от Windows Form Designer
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()
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private
components As System.ComponentModel.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
lblMessage As System.Windows.Forms.Label
Friend WithEvents txtValue As
System.Windows.Forms.TextBox
Friend WithEvents
btnOK As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()>
Private Sub
InitializeComponent()
Me.lblMessage
= New System.Windows.Forms.Label
Me.txtValue
= New System.Windows.Forms.TextBox
Me.btnOK
= New System.Windows.Forms.Button
Me.SuspendLayout()
'lblMessage
Me.lblMessage.Location
= New System.Drawing.Point(16, 8)
Me.lblMessage.Name =
"lblMessage"
Me.lblMessage.Size
= New System.Drawing.Size(208, 23)
Me.lblMessage.TabIndex
= 0
Me.lblMessage.Text
= "Type your value here"
'txtValue
Me.txtValue.Location
= New System.Drawing.Point(16, 48)
Me.txtValue.Name = "txtValue"
Me.txtValue.Size
= New System.Drawing.Size(160, 20)
Me.txtValue.TabIndex
= 1
Me.txtValue.Text
= ""
Фигура.5
Форма
с един етикет, една текстова кутия и един бутон-кодът се дава от VB.NET
'btnOK
Me.btnOK.Location
= New System.Drawing.Point(192, 48)
Me.btnOK.Name
= "btnOK"
Me.btnOK.TabIndex
= 2
Me.btnOK.Text
= "OK"
'Form1
Me.AutoScaleBaseSize
= New System.Drawing.Size(5, 13)
Me.ClientSize
= New System.Drawing.Size(292, 101)
Me.Controls.Add(Me.btnOK)
Me.Controls.Add(Me.txtValue)
Me.Controls.Add(Me.lblMessage)
Me.Name
= "Form1"
Me.Text
= "First Windows Forms example"
Me.ResumeLayout(False)
End Sub
#End Region
End Class