كيفية القيام بما يلي: عنصر تحكم محرر تعليمات برمجية (Visual أساسى)

Visual Studioهو محرر تعليمات برمجية في محرر نص يتوافق مع لغة الخدمات مثل كـ Visual Basic، Visual C++، و #Visual C. نص هو كتابة إلى مخزن مؤقت dهوplays ذلك في مستند نصي. باستخدام Visual Studioالكائنات طراز "التنفيذ التلقائي محرر"؛ يمكنك معالجة نص في الخلفية في احتياطي للنص أو في عرض.

الأربعة الرئيسية الكائنات المستخدمة للتحكم في نص في تعليمات برمجية محرر هي:

اسم الكائن

الوصف

TextSelection

يستخدم إلى معالجة نص في عرض. TextSelectionكائن يمثل يؤشر الإدراج (أو علامة الإقحام) أو نص محدد في مستند مرئي.

TextPoint

موضع ثابت في نص احتياطي.

EditPoint2

مماثلة إلى TextPointالكائن، ولكن يمكن نقلها ويمكن تعديل نص في احتياطي.

VirtualPoint

مماثلة إلى TextPointالكائن، إلا أنه يحتوي على وظائف إضافى إلى تحديد موقع نص المواضع في المساحة الظاهرية.

كائنين رئيسية تستخدمها إلى التعامل مع تعليمات برمجية يتم ediإلىr TextSelectionو EditPoint2الكائنات. الاختلافات الأساسية بينهم:

  • TextSelectionتمثل مرئي نص تحديد. تغيير موضعه التغييرات تحديد في عرض. EditPoint2هو لا ترتبط بأي مكون واجهة مستخدم، وبالتالي تغيير موضعه بتغيير أي شئ في عرض.

  • لأن TextSelectionيمثل تحديد مرئياً، هناك واحد فقط TextSelectionكائن كل مستند. بينما يمكن أن يكون لديك عدة TextSelectionالكائنات في مستند، فكافة تشير إلى نفس تحديد مرئياً و كافة لديهم نفس الموضع. يمكنك الحصول على كـ الكثير من EditPoint2الالكائنات كـ الذي تريده، والتي يمكن أن تحتوي الجميع مواضع مختلفة.

  • وظائف TextSelectionالكائن مصممة لجعل المراسلات رأس برأس لإجراءات مستخدم أثناء الأساليب الخاصة EditPoint2عدم. كنتيجة، بعض EditPoint2وظائف إجراء الأشياء التي لا توجد واحدة TextSelectionيمكن تنفيذ أسلوب، بينما البعض EditPoint2وظائف أكثر استخداماً في دالة من TextSelectionالأساليب. وهذا هو أيضا السبب في ذلك TextSelectionهو أكثر ثراء في خصائص و أساليب من EditPoint2.

يمكنك باستخدام هذه الكائنات:

  • تحديد إضافة ويحذف، و تحريك نص في احتياطي أو في عرض.

  • تحريك يؤشر الإدراج حول احتياطي أو عرض.

  • وضع مسافة بادئة قبل نص في احتياطي أو عرض.

  • إدراج، قم بإزالة، و التنقل إلى إشارات مرجعية.

  • إضافة أو إزالة نص، بما في ذلك المسافات.

  • بحث أو استبدال نص استناداً إلى نمط معين.

  • قم بإنشاء قسم المخطط التفصيلي في تعليمات برمجية والنص.

  • استعلام معلومات حول the نص, such كـ نص موضع, الأعلى و أسفل of مستند, محدد نص ranges, و so forth.

تبين الأمثلة الماكرو التالية كيفية إلى الرجوع واستخدام الأعضاء طراز Auإلىmation Ediإلىr المختلفة. لمزيد من المعلومات حول كيفية إلى تشغيل تعليمات برمجية للنموذج، راجع كيفية القيام بما يلي: ترجمة و تشغيل أمثلة تعليمات برمجية طراز كائن للتنفيذ التلقائي.

لمزيد من الأمثلة demonstrating استخدام طراز التنفيذ التلقائي "محرر"، راجع الماكرو "تدقيق إملائي" و الأمثلة الأخرى تشغيل "‏‫النماذج التنفيذ التلقائي" لبرنامج ‏‫Visual Studio ( https://msdn2.microsoft.com/en-us/vstudio/aa718336.aspx ) موقع ويب.

ملاحظة

مربعات حوار و commوs القائمة التي تظهر التي قد تختلف عن تلك الموضحة في التعليمات استناداً إلى إعدادات النشطة أو نسخة الخاص بك. تم تطوير هذه الإجراءات باستخدام "إعدادات تطوير عامة" نشطة. To change your settings, choose Import and Export Settings on the Tools menu. لمزيد من المعلومات، راجع العمل مع إعدادات.

HTMLWindow3,vsHTMLPanesوvsHTMLViewsتمت إضافتها باستخدام عرض "انقسام" في المقدمةVisual Studio 2008محرر HTML. فصل تقسيم العرض علامة تبويب وعناصر HTML تحرير نافذة عرض. تبديل عرض (للتصميم "أو" مصدر ") لا بالضرورة يعني تبديل علامة تبويب (التصميم/الانقسام/مصدر). على سبيل المثال، عند النقر فوق علامة تبويب فصل، التبديل بين طرق العرض بين تصميم و المصدر لا يتم تغيير علامة تبويب، يقوم بتنشيط أو إلغاء التنشيط أجزاء التصميم و المصدر في عرض "فصل" فقط.

مثال

ماكرو مثال ل ActivePoint. وهذا مثال كما يوضح الاستخدام StartOfLine، DisplayColumn، و EndOfLine. قبل تشغيل هذا المثال، فتح ملف تعليمات برمجية أو مستند نصي في Visual Studio، إضافة جزءا من النص، حدد بعض النص.

' Macro example for TextSelection.ActivePoint.
'
Sub ActivePointExample()
    ' Before running this example, open a text document.
    Dim objSel As TextSelection = DTE.ActiveDocument.Selection
    Dim objActive As VirtualPoint = objSel.ActivePoint
     ' Collapse the selection to the beginning of the line.
    objSel.StartOfLine()
     ' objActive is "live", tied to the position of the actual 
     ' selection, so it will reflect the new position.
    Dim iCol As Long = objActive.DisplayColumn
     ' Move the selection to the end of the line.
        objSel.EndOfLine()

    MsgBox("The length of the insertion point line is " & _
    (objActive.DisplayColumn - iCol) & " display characters.")
End Sub

ماكرو مثال ل AnchorPoint. وهذا مثال كما يوضح استخدم DisplayColumn، Line، StartOfDocumentو EndOfDocument. قبل تشغيل هذا المثال، فتح ملف تعليمات برمجية أو مستند نصي في Visual Studio، إضافة جزءا من النص، حدد بعض النص.

' Macro example for TextSelection.AnchorPoint.
'
Sub AnchorPointExample()
    ' Before running this example, open a text document.
    Dim objSel As TextSelection = DTE.ActiveDocument.Selection
    Dim objAnchor As VirtualPoint = objSel.AnchorPoint
    ' objAnchor is "live", tied to the position of the actual 
    ' selection, so it will reflect changes. iCol and iRow are created 
    ' here to save a "snapshot" of the anchor point's position at this 
    ' time.
    Dim iCol As Long = objAnchor.DisplayColumn
    Dim iRow As Long = objAnchor.Line
    ' As the selection is extended, the active point moves but the 
    ' anchor point remains in place.
    objSel.StartOfDocument(True)
    objSel.EndOfDocument(True)

    If (iCol = objAnchor.DisplayColumn And iRow = objAnchor.Line) Then
        MsgBox("The anchor point has remained in place at row " & _
        iRow & ", display column " & iCol)
    End If
End Sub

ماكرو مثال ل Insert. This مثال also illustrates the استخدم ofIsEmpty,WordLeft,WordRight,Text,Delete, وMoveToPoint. قبل تشغيل هذا المثال، يمكنك فتح ملف تعليمات برمجية أو مستند نصي في Visual Studioو إضافة بعض نص إلى it.

' Macro example for TextSelection.Insert.
'
Sub InsertExample()
    ' Before running this example, open a text document.
    Dim objSel As TextSelection = DTE.ActiveDocument.Selection
    If objSel.IsEmpty Then
        ' If there is no text selected, swap the words before and after 
        ' the insertion point. We begin by selecting the word before 
        ' the insertion point.
        objSel.WordLeft(True)
        If Not objSel.IsEmpty Then
            ' We can continue only if the selection was not already at 
            ' the beginning of the document.
            Dim strBefore As String = objSel.Text

            ' The text is saved in strBefore; now delete it and move 
            ' past the following word.
            objSel.Delete()
            objSel.WordRight(True)
            If objSel.Text.StartsWith(" ") Or _
            objSel.Text.StartsWith(Microsoft.VisualBasic. _
            ControlChars.Tab) Then
                ' The previous call to WordRight may have skipped some 
                ' white space instead of an actual word. In that case, 
                 ' we should call it again.
                objSel.WordRight(True)
            End If

            ' Insert the new text at the end of the selection.
            objSel.Insert(strBefore, _
            vsInsertFlags.vsInsertFlagsInsertAtEnd)
        End If
    Else
        ' If some text is selected, replace the following word with the 
        ' selected text.
        Dim strSelected As String = objSel.Text

        objSel.MoveToPoint(objSel.BottomPoint)
        objSel.WordRight(True)
        If objSel.Text.StartsWith(" ") Or _
        objSel.Text.StartsWith(Microsoft.VisualBasic. _
        ControlChars.Tab) Then
            ' The previous call to WordRight may have skipped some 
            ' white space instead of an actual word. In that case, we 
            ' should call it again.
            objSel.WordRight(True)
        End If

        ' Insert the text, overwriting the existing text and leaving 
        ' the selection containing the inserted text.
        objSel.Insert(strSelected, _
        vsInsertFlags.vsInsertFlagsContainNewText)
    End If
End Sub

ماكرو مثال ل FindPattern. وهذا مثال كما يوضح استخدم SelectLine. قبل تشغيل هذا المثال، تحتاج إلى فتح مستند نصي أو ملف التعليمات برمجية في Visual Studioو إضافة جزءا من نص إلى it.

' Macro example for TextSelection.FindPattern.
'
Sub FindPatternExample()
    ' Before running this example, open a text document.
    Dim objSel As TextSelection = DTE.ActiveDocument.Selection

    ' Advance to the next Visual Basic function beginning or end by 
    ' searching for  "Sub" with white space before and after it.
    If objSel.FindPattern(":WhSub:Wh", _
    vsFindOptions.vsFindOptionsRegularExpression) Then
        ' Select the entire line.
        objSel.SelectLine()
    End If
End Sub

ماكرو مثال ل OutlineSection. This مثال also illustrates the استخدم ofStartOfDocument,Line,LineCharOffset,FindPattern,SwapAnchor,MoveToLineAndOffsetوLineDown. قبل تشغيل هذا مثال، قم بفتح مستند التعليمات برمجية في Visual Studioالتي تحتوي على #if _DEBUG…#endifحظر.

' Macro example for TextSelection.OutlineSection.
'
Sub OutlineSectionExample()
    ' Before running this example, open a code document
    ' containing a #if _DEBUG…#endif block.
    Dim objSel As TextSelection = DTE.ActiveDocument.Selection

    ' Move to the beginning of the document so we can iterate over the 
    ' whole thing.
    objSel.StartOfDocument()
    While objSel.FindPattern("#if _DEBUG")
        ' If we found the beginning of a debug-only section, save the 
        ' position.
        Dim lStartLine As Long = objSel.TopPoint.Line
        Dim lStartColumn As Long = objSel.TopPoint.LineCharOffset

        ' Look for the end.
        If objSel.FindPattern("#endif") Then
            ' Select the entire section and outline it.
            objSel.SwapAnchor()
            objSel.MoveToLineAndOffset(lStartLine, lStartColumn, True)
            objSel.OutlineSection()
            objSel.LineDown()
        End If
    End While
End Sub

يفتح المثال الماكرو مستند نصي و يقوم بإنشاء قائمة commوs كافة متوفر في هذا المستند.

' Macro example
  ' This generates a text document listing all available command names.
Sub CommandNamesCollapseExample()
  Dim Cmd As Command
  Dim Commands As Commands = DTE.Commands 
  Dim PrjItem As ProjectItem
  Dim Doc As Document
  Dim TxtDoc As TextDocument
  DTE.ItemOperations.NewFile ("General\Text File")
  Set Doc = ActiveDocument
  Set TxtDoc = Doc.Object("TextDocument")
  For Each Cmd In Commands
  If (Cmd.Name <> "") Then
    TxtDoc.Selection.Text = Cmd.Name & vbLF
    TxtDoc.Selection.Collapse
  End If
  Next
End Sub

الماكرو مثال HTMLWindowالكائن. This مثال also illustrates the استخدم ofActiveDocument,ActiveWindow,Window,CurrentTab,CurrentTabObject,ActivePane,StartPoint,CreateEditPoint,FindPatternوInsertFromFile. قبل تشغيل هذا مثال، قم بفتح مستند HTML في Visual Studio.

' Macro example for HTMLWindow object

Sub HTMLWindowExample()
   ' Open an HTML document before running this sample.
   If TypeOf ActiveDocument.ActiveWindow.Object Is HTMLWindow Then
      ' Ask the user for a file to insert into the body of the HTML 
      ' document. This file should be an HTML fragment.
      Dim strFile As String = InputBox("Enter the name of a file to _
      insert at the end of the HTML document:")
      ' Get the HTMLWindow object and determin which tab is currently 
      ' active.
      Dim objHTMLWin As HTMLWindow = ActiveDocument.ActiveWindow.Object
      Dim Tab As vsHTMLTabs = objHTMLWin.CurrentTab

      ' Switch to the "source" tab.
      objHTMLWin.CurrentTab = vsHTMLTabs.vsHTMLTabsSource

      ' Get an EditPoint at the start of the text.
      Dim objTextWin As TextWindow = objHTMLWin.CurrentTabObject
      Dim objEP As EditPoint = _
      objTextWin.ActivePane.StartPoint.CreateEditPoint

      ' Look for the end of the document body.
      If objEP.FindPattern("</body>") Then
         ' Insert the contents of the file.
         objEP.InsertFromFile(strFile)
      End If

      ' Switch back to the original view of the HTML file.
       objHTMLWin.CurrentTab = Tab
   Else
      MsgBox("You must open an HTML document.")
   End If
End Sub

راجع أيضًا:

المهام

كيفية القيام بما يلي: الصفات المميزة لإطار تغيير

كيفية القيام بما يلي: قم بإنشاء إضافة-في

الإرشادات التفصيلية: إنشاء معالج

المبادئ

مخطط نموذج كائن تلقائي

موارد أخرى

إنشاء و التحكم في بيئة Windows

إنشاء إضافة-زر 'Ins' ومعالجات

التنفيذ التلقائي والمرجع الامتداد