frmFind.vb
Upload User: wuanfu007
Upload Date: 2021-01-16
Package Size: 501k
Code Size: 6k
Category:

.net

Development Platform:

DOS

  1. Public Class frmFind
  2.     Inherits System.Windows.Forms.Form
  3.     Dim selPosition As Integer = 1
  4. #Region " Windows Form Designer generated code "
  5.     Public Sub New()
  6.         MyBase.New()
  7.         'This call is required by the Windows Form Designer.
  8.         InitializeComponent()
  9.         'Add any initialization after the InitializeComponent() call
  10.     End Sub
  11.     'Form overrides dispose to clean up the component list.
  12.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  13.         If disposing Then
  14.             If Not (components Is Nothing) Then
  15.                 components.Dispose()
  16.             End If
  17.         End If
  18.         MyBase.Dispose(disposing)
  19.     End Sub
  20.     'Required by the Windows Form Designer
  21.     Private components As System.ComponentModel.IContainer
  22.     'NOTE: The following procedure is required by the Windows Form Designer
  23.     'It can be modified using the Windows Form Designer.  
  24.     'Do not modify it using the code editor.
  25.     Friend WithEvents Label1 As System.Windows.Forms.Label
  26.     Friend WithEvents txtFindString As System.Windows.Forms.TextBox
  27.     Friend WithEvents cmdFind As System.Windows.Forms.Button
  28.     Friend WithEvents cmdCancel As System.Windows.Forms.Button
  29.     Friend WithEvents chxMatchCase As System.Windows.Forms.CheckBox
  30.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  31.         Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmFind))
  32.         Me.Label1 = New System.Windows.Forms.Label
  33.         Me.txtFindString = New System.Windows.Forms.TextBox
  34.         Me.cmdFind = New System.Windows.Forms.Button
  35.         Me.cmdCancel = New System.Windows.Forms.Button
  36.         Me.chxMatchCase = New System.Windows.Forms.CheckBox
  37.         Me.SuspendLayout()
  38.         '
  39.         'Label1
  40.         '
  41.         Me.Label1.AutoSize = True
  42.         Me.Label1.Location = New System.Drawing.Point(19, 17)
  43.         Me.Label1.Name = "Label1"
  44.         Me.Label1.Size = New System.Drawing.Size(59, 12)
  45.         Me.Label1.TabIndex = 0
  46.         Me.Label1.Text = "查找内容:"
  47.         '
  48.         'txtFindString
  49.         '
  50.         Me.txtFindString.Location = New System.Drawing.Point(106, 9)
  51.         Me.txtFindString.Name = "txtFindString"
  52.         Me.txtFindString.Size = New System.Drawing.Size(201, 21)
  53.         Me.txtFindString.TabIndex = 1
  54.         '
  55.         'cmdFind
  56.         '
  57.         Me.cmdFind.Location = New System.Drawing.Point(55, 57)
  58.         Me.cmdFind.Name = "cmdFind"
  59.         Me.cmdFind.Size = New System.Drawing.Size(90, 24)
  60.         Me.cmdFind.TabIndex = 2
  61.         Me.cmdFind.Text = "查找下一个"
  62.         '
  63.         'cmdCancel
  64.         '
  65.         Me.cmdCancel.Location = New System.Drawing.Point(217, 57)
  66.         Me.cmdCancel.Name = "cmdCancel"
  67.         Me.cmdCancel.Size = New System.Drawing.Size(90, 25)
  68.         Me.cmdCancel.TabIndex = 3
  69.         Me.cmdCancel.Text = "取消"
  70.         '
  71.         'chxMatchCase
  72.         '
  73.         Me.chxMatchCase.AutoSize = True
  74.         Me.chxMatchCase.Location = New System.Drawing.Point(322, 12)
  75.         Me.chxMatchCase.Name = "chxMatchCase"
  76.         Me.chxMatchCase.Size = New System.Drawing.Size(84, 16)
  77.         Me.chxMatchCase.TabIndex = 5
  78.         Me.chxMatchCase.Text = "区分大小写"
  79.         '
  80.         'frmFind
  81.         '
  82.         Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
  83.         Me.ClientSize = New System.Drawing.Size(421, 105)
  84.         Me.Controls.Add(Me.chxMatchCase)
  85.         Me.Controls.Add(Me.cmdCancel)
  86.         Me.Controls.Add(Me.cmdFind)
  87.         Me.Controls.Add(Me.txtFindString)
  88.         Me.Controls.Add(Me.Label1)
  89.         Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
  90.         Me.MaximizeBox = False
  91.         Me.MinimizeBox = False
  92.         Me.Name = "frmFind"
  93.         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  94.         Me.Text = "查找与替换"
  95.         Me.ResumeLayout(False)
  96.         Me.PerformLayout()
  97.     End Sub
  98. #End Region
  99.     Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click
  100.         Dim srchMode As Microsoft.VisualBasic.CompareMethod
  101.         If chxMatchCase.Checked Then
  102.             srchMode = CompareMethod.Binary
  103.         Else : srchMode = CompareMethod.Text
  104.         End If
  105.         selPosition = InStr(selPosition, FrmMainObj.rtbEditor.Text, txtFindString.Text, srchMode)
  106.         If selPosition = 0 Then
  107.             MsgBox("未找到所查找的内容!")
  108.             Exit Sub
  109.         End If
  110.         FrmMainObj.rtbEditor.Select(selPosition - 1, txtFindString.Text.Length)
  111.         FrmMainObj.rtbEditor.ScrollToCaret()
  112.         Me.TopMost = True
  113.         FrmMainObj.rtbEditor.Focus()
  114.         If selPosition = 0 Then
  115.             selPosition = 1
  116.         Else
  117.             selPosition = selPosition + txtFindString.Text.Length
  118.         End If
  119.     End Sub
  120.     Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
  121.         Me.Close()
  122.     End Sub
  123.     '  Private Sub BtnReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReplace.Click
  124.     '    
  125.     '    FrmMainObj.rtbEditor.SelectedText = Replace(FrmMainObj.rtbEditor.Text, FrmMainObj.rtbEditor.SelectedText, Me.TxtReplace.Text)
  126.     '   If selPosition = 1 Then
  127.     '   cmdFind_Click(sender, e)
  128.     '   FrmMainObj.rtbEditor.Text = FrmMainObj.rtbEditor.Text.Remove(selPosition, txtFindString.Text.Length)
  129.     '     FrmMainObj.rtbEditor.Text = FrmMainObj.rtbEditor.Text.Insert(selPosition, TxtReplace.Text)
  130.     ' Else
  131.     '      If selPosition <> 0 Then
  132.     '  FrmMainObj.rtbEditor.Text = FrmMainObj.rtbEditor.Text.Remove(selPosition - 1, txtFindString.Text.Length)
  133.     '       '       FrmMainObj.rtbEditor.Text = FrmMainObj.rtbEditor.Text.Insert(selPosition - 1, TxtReplace.Text)
  134.     '      cmdFind_Click(sender, e)
  135.     '     End If
  136.     '     End If
  137.     'Else
  138.     ' FrmMainObj.rtbEditor.Text = FrmMainObj.rtbEditor.Text.Insert(selPosition, TxtReplace.Text)
  139.     ' End If
  140.     '  End Sub
  141.     '  Private Sub BtnReplaceAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReplaceAll.Click
  142.     '  Do
  143.     '     cmdFind_Click(sender, e)
  144.     '    BtnReplace_Click(sender, e)
  145.     '       Loop Until selPosition = 0
  146.     '   End Sub
  147. End Class