⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmlinenum.vb

📁 一个简单的文本编辑器。
💻 VB
字号:
Public Class frmLineCount
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    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 btnInsert As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents btnClose As System.Windows.Forms.Button
    Friend WithEvents chkIsAll As System.Windows.Forms.CheckBox
    Friend WithEvents updBeginNum As System.Windows.Forms.NumericUpDown
    Friend WithEvents udpSpace As System.Windows.Forms.NumericUpDown
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnInsert = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.updBeginNum = New System.Windows.Forms.NumericUpDown
        Me.udpSpace = New System.Windows.Forms.NumericUpDown
        Me.btnClose = New System.Windows.Forms.Button
        Me.chkIsAll = New System.Windows.Forms.CheckBox
        CType(Me.updBeginNum, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.udpSpace, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnInsert
        '
        Me.btnInsert.Location = New System.Drawing.Point(224, 24)
        Me.btnInsert.Name = "btnInsert"
        Me.btnInsert.Size = New System.Drawing.Size(120, 24)
        Me.btnInsert.TabIndex = 0
        Me.btnInsert.Text = "插入"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(16, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(66, 17)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "起始行号:"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(8, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(103, 17)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "与正文间隔空格:"
        '
        'updBeginNum
        '
        Me.updBeginNum.Location = New System.Drawing.Point(112, 16)
        Me.updBeginNum.Name = "updBeginNum"
        Me.updBeginNum.Size = New System.Drawing.Size(88, 21)
        Me.updBeginNum.TabIndex = 3
        Me.updBeginNum.Value = New Decimal(New Integer() {1, 0, 0, 0})
        '
        'udpSpace
        '
        Me.udpSpace.Location = New System.Drawing.Point(112, 48)
        Me.udpSpace.Name = "udpSpace"
        Me.udpSpace.Size = New System.Drawing.Size(88, 21)
        Me.udpSpace.TabIndex = 4
        Me.udpSpace.Value = New Decimal(New Integer() {2, 0, 0, 0})
        '
        'btnClose
        '
        Me.btnClose.Location = New System.Drawing.Point(224, 64)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.Size = New System.Drawing.Size(120, 24)
        Me.btnClose.TabIndex = 5
        Me.btnClose.Text = "关闭"
        '
        'chkIsAll
        '
        Me.chkIsAll.Location = New System.Drawing.Point(16, 80)
        Me.chkIsAll.Name = "chkIsAll"
        Me.chkIsAll.Size = New System.Drawing.Size(120, 24)
        Me.chkIsAll.TabIndex = 6
        Me.chkIsAll.Text = "全文插入行号"
        '
        'frmLineCount
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(368, 118)
        Me.ControlBox = False
        Me.Controls.Add(Me.chkIsAll)
        Me.Controls.Add(Me.btnClose)
        Me.Controls.Add(Me.udpSpace)
        Me.Controls.Add(Me.updBeginNum)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnInsert)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmLineCount"
        Me.Text = "插入行号"
        Me.TopMost = True
        CType(Me.updBeginNum, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.udpSpace, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public rt1 As RichTextBox = Nothing

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Visible = False
    End Sub

    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        Insert()
    End Sub

    Private Sub Insert()
        If Me.rt1 Is Nothing Then
            Exit Sub
        End If
        Dim startline, endline As Integer

        If Me.chkIsAll.Checked Then
            Me.rt1.SelectAll()
            
        Else
            If Me.rt1.SelectionLength = 0 Then
                Exit Sub
            End If
           
        End If


        Dim strReader As System.IO.StringReader
        strReader = New System.IO.StringReader(Me.rt1.SelectedText)

        Dim i As Integer
        Dim ModifyStr As New ArrayList
        Dim str As String
        str = strReader.ReadLine()
        i = 0
        While Not (str Is Nothing)
            str = CStr(Me.updBeginNum.Value + i) & Space(Me.udpSpace.Value) & str
            i += 1
            ModifyStr.Add(str)
            str = strReader.ReadLine
        End While

        Dim retStr As String = ""
        For i = 0 To ModifyStr.Count - 2
            retStr = retStr & ModifyStr(i) & Chr(13) & Chr(10)
        Next

        '最后一行不加回车换行符
        retStr = retStr & ModifyStr(i)
        Me.rt1.SelectedText = retStr
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -