📄 webcontrolsizeform.vb
字号:
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Web.UI.WebControls
Namespace WroxDesignVB.Design
'/ <summary>
'/ Summary description for WebControlSizeForm.
'/ </summary>
Public Class WebControlSizeForm : Inherits System.Windows.Forms.Form
Private label1 As System.Windows.Forms.Label
Private label2 As System.Windows.Forms.Label
Private txtWidth As System.Windows.Forms.TextBox
Private txtHeight As System.Windows.Forms.TextBox
Private grpUnit As System.Windows.Forms.GroupBox
Private WithEvents btnAccept As System.Windows.Forms.Button
Private WithEvents btnCancel As System.Windows.Forms.Button
'/ <summary>
'/ Required designer variable.
'/ </summary>
Private components As System.ComponentModel.Container = Nothing
Public Sub New()
'
' Required for Windows Form Designer support
'
InitializeComponent()
'
' TODO: inherits Add any constructor code after InitializeComponent call
'
End Sub
'/ <summary>
'/ Clean up any resources being used.
'/ </summary>
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
#Region "Windows Form Designer generated code"
'/ <summary>
'/ Required method for Designer support - do not modify
'/ the contents of me method with the code editor.
'/ </summary>
Private Sub InitializeComponent()
Me.btnCancel = New System.Windows.Forms.Button()
Me.grpUnit = New System.Windows.Forms.GroupBox()
Me.btnAccept = New System.Windows.Forms.Button()
Me.txtWidth = New System.Windows.Forms.TextBox()
Me.txtHeight = New System.Windows.Forms.TextBox()
Me.label1 = New System.Windows.Forms.Label()
Me.label2 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
' btnCancel
'
Me.btnCancel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left)
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.btnCancel.Location = New System.Drawing.Point(84, 88)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(64, 24)
Me.btnCancel.TabIndex = 0
Me.btnCancel.Text = "Cancel"
'
' grpUnit
'
Me.grpUnit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.grpUnit.Location = New System.Drawing.Point(164, 4)
Me.grpUnit.Name = "grpUnit"
Me.grpUnit.Size = New System.Drawing.Size(136, 44)
Me.grpUnit.TabIndex = 3
Me.grpUnit.TabStop = False
Me.grpUnit.Text = "UnitType"
'
' btnAccept
'
Me.btnAccept.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left)
Me.btnAccept.DialogResult = System.Windows.Forms.DialogResult.OK
Me.btnAccept.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.btnAccept.Location = New System.Drawing.Point(12, 88)
Me.btnAccept.Name = "btnAccept"
Me.btnAccept.Size = New System.Drawing.Size(64, 24)
Me.btnAccept.TabIndex = 0
Me.btnAccept.Text = "Accept"
'
' txtWidth
'
Me.txtWidth.Location = New System.Drawing.Point(64, 12)
Me.txtWidth.Name = "txtWidth"
Me.txtWidth.Size = New System.Drawing.Size(80, 21)
Me.txtWidth.TabIndex = 0
Me.txtWidth.Text = ""
'
' txtHeight
'
Me.txtHeight.Location = New System.Drawing.Point(64, 36)
Me.txtHeight.Name = "txtHeight"
Me.txtHeight.Size = New System.Drawing.Size(80, 21)
Me.txtHeight.TabIndex = 0
Me.txtHeight.Text = ""
'
' label1
'
Me.label1.Location = New System.Drawing.Point(16, 16)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(40, 16)
Me.label1.TabIndex = 0
Me.label1.Text = "Width: inherits"
'
' label2
'
Me.label2.Location = New System.Drawing.Point(16, 40)
Me.label2.Name = "label2"
Me.label2.Size = New System.Drawing.Size(48, 16)
Me.label2.TabIndex = 1
Me.label2.Text = "Heigth: inherits"
'
' WebControlSizeForm
'
Me.AcceptButton = Me.btnAccept
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.BackColor = System.Drawing.Color.FromArgb(CType(153, System.Byte), _
CType(153, System.Byte), CType(255, System.Byte))
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(310, 120)
Me.ControlBox = False
Me.Controls.AddRange(New System.Windows.Forms.Control() { _
Me.btnCancel, _
Me.btnAccept, _
Me.grpUnit, _
Me.txtHeight, _
Me.txtWidth, _
Me.label2, _
Me.label1})
Me.Font = New System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, System.Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me.Name = "WebControlSizeForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Edit the WebControl Size"
Me.ResumeLayout(False)
End Sub
#End Region
Private _size As WebControlSize
Private Sub WebControlSizeForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim values As String() = System.Enum.GetNames(GetType(UnitType))
Dim x As Integer = 10 'Default left margin inside the group
Dim y As Integer = 20 'Default height of each option
Dim sel As Integer = 0 'The index of the selected option
Dim btn As System.Windows.Forms.RadioButton
Dim i As Integer
For i = 0 To values.Length - 1
btn = New System.Windows.Forms.RadioButton()
btn.Location = New Point(x, y * (i + 1))
btn.Text = values(i)
If (btn.Text = _size.Height.Type.ToString()) Then sel = i
grpUnit.Controls.Add(btn)
Next
grpUnit.Height = y * values.Length + y * 2
Me.Height = grpUnit.Height + 40
CType(grpUnit.Controls(sel), System.Windows.Forms.RadioButton).Checked = True
txtHeight.Text = _size.Height.Value.ToString()
txtWidth.Text = _size.Width.Value.ToString()
End Sub
Private Sub btnAccept_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAccept.Click
Try
Dim btn As System.Windows.Forms.RadioButton = Nothing
Dim current As System.Windows.Forms.RadioButton
For Each current In grpUnit.Controls
If (current.Checked) Then
btn = current
Exit For
End If
Next
Dim type As UnitType = CType(System.Enum.Parse(GetType(UnitType), btn.Text), UnitType)
Dim h As Unit = New Unit(Integer.Parse(txtHeight.Text), type)
Dim w As Unit = New Unit(Integer.Parse(txtWidth.Text), type)
_size = New WebControlSize(h, w)
Close()
Catch
Throw New ArgumentException("The values are invalid!")
End Try
End Sub
Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Close()
End Sub
Friend Property CurrentSize() As WebControlSize
Get
Return _size
End Get
Set(ByVal Value As WebControlSize)
_size = Value
End Set
End Property
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -