17-10-12, 05:56 PM
كاتب الموضوع : Boutemine Oualid
السلام عليكم و رحمة الله و بركاتههذا البرنامج الصغير يوضح كيفية استغلال محرر النصوص وورد لتصحيح الأخطاء الكتابية.
كود :
'Author : Boutemine Oualid
'Add a reference to : Microsoft Word Objects Library (COM)
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop
Public Class frmMain
'نسخة تطبيق من برنامج الوورد
Dim WordApp As New Word.Application()
'محتويات الملف الجديد
Dim dRange As Word.Range
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'اخفاء نافذة البرنامج أثناء عملية التصحيح
WordApp.Visible = False
WordApp.ShowWindowsInTaskbar = False
'اضافة مستند جديد
Dim document As Word.Document = WordApp.Documents.Add()
'التأشير على محتويات المستند الجديد
dRange = document.Range
End Sub
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
lstWrongWords.Items.Clear()
'اختيار لغة الكتابة
'اللغة العربية
dRange.LanguageID = Word.WdLanguageID.wdArabic
'وضع النص المراد تصحيحه في مستند الوورد الذي أضقناه
dRange.Text = txtText.Text
'مجموعة الكلمات الخاطئة
Dim SpellCollection As Word.ProofreadingErrors
'قراءة الكلمات الخاطئة
SpellCollection = dRange.SpellingErrors
'ان وجدت كلمات خاطئة اذن
If SpellCollection.Count > 0 Then
Dim iword As Integer
Dim newWord As String
For iword = 1 To SpellCollection.Count
newWord = SpellCollection.Item(iword).Text
lstWrongWords.Items.Add(newWord)
Next
Else
MsgBox("النص لا توجد به أخطاء", MsgBoxStyle.Information, "نتيجة المراقبة")
End If
End Sub
Private Sub frmMain_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
'اغلاق البرنامج دون القيام بعملية الحفظ
WordApp.Quit(False)
End Sub
Private Sub lstWrongWords_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstWrongWords.SelectedIndexChanged
lstSuggestions.Items.Clear()
'التأشير على لائحة الكلمات المحتملة لتصحيح الكلمة الخاطئة
Dim suggestions As Word.SpellingSuggestions = dRange.SpellingErrors(lstWrongWords.SelectedIndex + 1).GetSpellingSuggestions()
Dim i As Integer
For i = 1 To suggestions.Count
lstSuggestions.Items.Add(suggestions(i).Name)
Next
End Sub
End Class