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() End If End If 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 RichTextBox1 As System.Windows.Forms.RichTextBox Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog Private Sub InitializeComponent() Me.RichTextBox1 = New System.Windows.Forms.RichTextBox() Me.MainMenu1 = New System.Windows.Forms.MainMenu() Me.MenuItem1 = New System.Windows.Forms.MenuItem() Me.MenuItem2 = New System.Windows.Forms.MenuItem() Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog() Me.SuspendLayout() ' 'RichTextBox1 ' Me.RichTextBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.RichTextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(178, Byte)) Me.RichTextBox1.Location = New System.Drawing.Point(8, 8) Me.RichTextBox1.Name = "RichTextBox1" Me.RichTextBox1.Size = New System.Drawing.Size(584, 244) Me.RichTextBox1.TabIndex = 0 Me.RichTextBox1.Text = "" ' 'MainMenu1 ' Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1}) ' 'MenuItem1 ' Me.MenuItem1.Index = 0 Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2}) Me.MenuItem1.Text = "File" ' 'MenuItem2 ' Me.MenuItem2.Index = 0 Me.MenuItem2.Text = "Open" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(600, 258) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.RichTextBox1}) Me.Menu = Me.MainMenu1 Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click OpenFileDialog1.DefaultExt = "TXT" OpenFileDialog1.Filter = "Text Files|*.TXT" OpenFileDialog1.FilterIndex = 1 OpenFileDialog1.ShowDialog() If OpenFileDialog1.FileName = "" Then Exit Sub Dim TReader As System.IO.StreamReader TReader = New System.IO.StreamReader(OpenFileDialog1.FileName, System.Text.Encoding.Default) Dim Rt As New RichTextBox() Rt.Font = New Font(Rt.Font.Name, 20, FontStyle.Bold) Rt.SelectionAlignment = HorizontalAlignment.Right Rt.Text = TReader.ReadToEnd TReader.Close() TReader = Nothing ' تلوين علامات الترقيم Dim Ch() As Char = {".", ":", "؟", "?", "!", "،", "ـ ", "(", ")", "[", "]", "{", "}", """"} Dim Pos As Integer = -1 Do Pos = Rt.Find(Ch, Pos + 1) If Pos = -1 Then Exit Do Rt.SelectionStart = Pos Rt.SelectionLength = 1 Rt.SelectionColor = Color.Blue Loop ' تلوين الكلمات التي تبدأ بحرف @ Dim EndOfWord As Integer, L As Integer = Rt.TextLength Pos = -1 Ch = New Char() {" ", vbCr, ".", ":", "؟", "?", "!", "،", "ـ ", "(", ")", "[", "]", "{", "}", """"} Do Pos = Rt.Find("@", Pos + 1, RichTextBoxFinds.MatchCase) If Pos = -1 Or Pos >= L - 1 Then Exit Do ' حذف علامة @.. لاحظ أنّها محدّدة الآن في النصّ Rt.SelectedText = "" ' الآن صارت بداية الكلمة في نفس موضع العلامة المحذوفة Rt.SelectionStart = Pos EndOfWord = Rt.Find(Ch, Pos) If EndOfWord = -1 Then ' هذه آخر كلمة في النصّ Rt.SelectionLength = L - Pos Else Rt.SelectionLength = EndOfWord - Pos End If Rt.SelectionColor = Color.Red Loop RichTextBox1.Rtf = Rt.Rtf End Sub Private Sub RichTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress Select Case e.KeyChar Case ".", ":", "؟", "?", "!", "،", "ـ ", "(", ")", "[", "]", "{", "}", """" RichTextBox1.SelectionColor = Color.Blue Case Else RichTextBox1.SelectionColor = Color.Black End Select End Sub End Class