form1.vb
来自「Visual Basic .NET程序设计教程源代码」· VB 代码 · 共 159 行
VB
159 行
Public Class Form1
Inherits System.Windows.Forms.Form
Dim strInput, Code, Record, c As String
Dim i%, length%, iAsc%
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
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
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.TextBox3 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(0, 8)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 0
Me.Label1.Text = "输入字符串"
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.Location = New System.Drawing.Point(8, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(48, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "加密"
'
'Button2
'
Me.Button2.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button2.Location = New System.Drawing.Point(8, 64)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(48, 23)
Me.Button2.TabIndex = 2
Me.Button2.Text = "解密"
'
'Button3
'
Me.Button3.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button3.Location = New System.Drawing.Point(8, 96)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(48, 23)
Me.Button3.TabIndex = 3
Me.Button3.Text = "清屏"
'
'TextBox1
'
Me.TextBox1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.TextBox1.Location = New System.Drawing.Point(72, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(208, 23)
Me.TextBox1.TabIndex = 4
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.TextBox2.Location = New System.Drawing.Point(72, 40)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(208, 23)
Me.TextBox2.TabIndex = 5
Me.TextBox2.Text = ""
'
'TextBox3
'
Me.TextBox3.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.TextBox3.Location = New System.Drawing.Point(72, 72)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(208, 23)
Me.TextBox3.TabIndex = 6
Me.TextBox3.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox3, Me.TextBox2, Me.TextBox1, Me.Button3, Me.Button2, Me.Button1, Me.Label1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strInput, Code, Record, c As String
Dim i%, length%, iAsc%
strInput = TextBox1.Text
length = Len(RTrim(strInput)) '去掉字符串右边的空格,求真正的长度
Code = ""
For i = 1 To length
c = Mid$(strInput, i, 1) '取第i个字符
Select Case c
Case "A" To "Z" '大写字母加序数5加密
iAsc = Asc(c) + 5
If iAsc > Asc("Z") Then iAsc = iAsc - 26 '加密后字母超过Z
Code = Code + Chr(iAsc)
Case "a" To "z"
iAsc = Asc(c) + 5 '小写字母加序数5加密
If iAsc > Asc("z") Then iAsc = iAsc - 26
Code = Code + Chr(iAsc)
Case Else '当第i个字符为其他字符时不加密
Code = Code + c
End Select
Next i
TextBox2.Text = Code '显示加密后的字符串
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?