مشاركة عبر


كيفية القيام بما يلي: إنشاء و عنصر تحكم أداة Windows

Windows في Visual Studioتقع في أي من فئتين: توثيق الإطارات أو أداة الإطارات. هو نافذة مستند يكون محتواه قابلة للتحرير بمحرر تعليمات برمجية، مثل كـ الملف النصي أو HTML أو تعليمات برمجية داخل clكـs. إطار الأدوات يحتوي على واحد أو أكثر عناصر التحكم، مثل الأزرار، النص ومربعات التحرير والسرد وما إلى ذلك. The Visual Studio integrated development بيئة (IDE) uses عناصر التحكم إلى perform tasks such كـ إعداد خيارات, viewing أخطاء, أو ‏‏تحرير مشروع عناصر. Some أمثلة of these are the إخراج نافذة, the مهمة قائمة, و the مربع الأدوات. The مربع الأدوات can be moved around the IDE freely أو docked مع غير ذلك أداة windows, و you can استخدم the LinkedWindows مجموعة إلى programmatically ارتباط أو إلغاء الارتباط أداة windows في the IDE. لمزيد من المعلومات، راجع كيفية القيام بما يلي: الصفات المميزة لإطار تغيير.

بالإضافة إلى استخدام "التنفيذ التلقائي" للتعامل مع إطارات الأدوات الموجودة، يمكنك أيضا إنشاء الخاصة بك أداة مخصصة الإطارات باستخدام CreateToolWindow2طريقة Windows2مجموعة.

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

The إجراء for creating a مخصص أداة نافذة هو:

  • إنشاء a مستخدم عنصر تحكم (using a Windows عنصر تحكم مكتبة مشروع)

  • إضافة desired عناصر التحكم تشغيل a نموذج (الأزرار, textboxes, و so تشغيل) و تعليمات برمجية.

  • يحول برمجياً the مشروع في a DLL.

  • إنشاء جديد Visual Studioإضافة-في المشروع (أو مشروع آخر، مثل مشروع تطبيق Windows).

  • استخدام CreateToolWindow2الأسلوب لإنشاء نافذة أداة مستخدم جديد لاستضافة عنصر تحكم.

قبل استدعاء CreateToolWindow2لإنشاء نافذة جديد لأداة، يجب أما تحريك عنصر التحكم مستخدم ( ControlObject) في نفس تجميع إضافة-في، أو تعيين كل من الالسمات تشغيل عنصر التحكم مستخدم لجعله مرئياً بشكل كامل إلى COM. (ل مثال، يتم الآن التدقيق من تسجيل ل توافق COM خيار في مشروع الترجمة بخيارات.) إذا لم تقم بذلك، ثم عنصر تحكم سوف لا يتم تنظيم بشكل صحيح CreateToolWindow2بإرجاع القيمة خالية.

بالإضافة إلى الأمثلة أدناه، ‏‫النماذج إطار أداة إضافى لكل لغة، إلى جانب غير ذلك تعليمات برمجية الأمثلة، تشغيل ‏‫النماذج التنفيذ التلقائي لبرنامج ‏‫Visual Studio موقع ويب.

ملاحظة

إذا حاولت تعيين أي من حالات vهوibility نافذة الأدوات الجديدة — مثل ارتفاع أو عرض موضع — قبل النافذة أداة هو vهوible، سوف تحصل على خطأ. تأكد من أن الإطار هو vهوible قبل محاولة تعيين هذه الخصائص.

ملاحظة

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

إنشاء مخصص أداة نافذة

يوضح المثال التالي كيف إلى إنشاء نافذة إلى ol في Visual Basicو #Visual C.

ملاحظة

يجب أن يتم تنفيذ التعليمة البرمجية التالية في إضافة-في؛ لا يمكن تنفيذ في ماكرو.

إلى إنشاء نافذة أداة مخصصة

  • إنشاء عنصر تحكم المستخدم في مشروع مكتبة التحكم Windows. قبول الاسم الافتراضي "Windowsعنصر تحكمLibrary1"، أو تأكد من أن تقوم بتغيير اسم asmPathمعلمة في تعليمات برمجية التالية بحيث يتطابق مع اسم المشروع عنصر تحكم مكتبة Windows الخاص بك.

    بدلاً من ذلك، في تعليمات برمجية الخاصة بك، يمكنك الإشارة إلى موجود عنصر تحكم المستخدم.

ملاحظة

يجب أن يكون لفئة عنصر تحكم مستخدم الخاص بك System.Runtime.InteropServices.GuidAttributeمرفقة إلى تعريف الفئة.

  1. إنشاء إضافة جديد-في مشروع.

    لمزيد من المعلومات، راجع كيفية القيام بما يلي: قم بإنشاء إضافة-في.

  2. باستبدال OnConnectionأسلوب إضافة-بما يلي:

    Public Sub OnConnection(ByVal application As Object, ByVal _
    connectMode As ext_ConnectMode, ByVal addInInst As Object, _
    ByRef custom As Array) Implements IDTExtensibility2.OnConnection
        Try
            ' ctlProgID - the ProgID for your user control.
            ' asmPath - the path to your user control DLL.
            ' guidStr - a unique GUID for the user control.
            Dim ctlProgID, asmPath, guidStr As String
            ' Variables for the new tool window that will hold
            ' your user control.
            Dim toolWins As EnvDTE80.Windows2
            Dim toolWin As EnvDTE.Window
            Dim objTemp As Object = Nothing
    
            _applicationObject = CType(application, DTE2)
            _addInInstance = CType(addInInst, AddIn)
            ctlProgID = "WindowsControlLibrary2.UserControl1"
            ' Replace the <Path to VS Project> with the path to
            ' the folder where you created the WindowsCotrolLibrary.
            ' Remove the line returns from the path before 
            ' running the add-in.
            asmPath = "<Path to VS Project>\My _
              Documents\Visual Studio 2005\Projects\ _
              WindowsControlLibrary2\WindowsControlLibrary2\_
              bin\Debug\WindowsControlLibrary2.dll"
            guidStr = "{E9C60F2B-F01B-4e3e-A551-C09C62E5F584}"
    
            toolWins = CType(_applicationObject.Windows, Windows2)
            ' Create the new tool window, adding your user control.
            toolWin = toolWins.CreateToolWindow2(_addInInstance, _
              asmPath, ctlProgID, "MyNewToolwindow", guidStr, objTemp)
            ' The tool window must be visible before you do anything 
            ' with it, or you will get an error.
            If Not toolWins Is Nothing Then
                toolWin.Visible = True
            End If
               ' Uncomment the code below to set the new tool window's
               ' height and width, and to close it.
            ' MsgBox("Setting the height to 500 and width to 400...")
            ' toolWin.Height = 500
            ' toolWin.Width = 400
            ' MsgBox("Closing the tool window...")
            ' toolWin.Close(vsSaveChanges.vsSaveChangesNo)
    
        Catch ex As Exception
            MsgBox("Exception: " & ex.ToString)
        End Try
    End Sub
    
    // Before running, add a reference to System.Windows.Forms, 
    // using System.Windows.Forms, to the top of the class.
    public void OnConnection(object application, 
    ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        try
        {
            // ctlProgID - the ProgID for your user control.
            // asmPath - the path to your user control DLL.
            // guidStr - a unique GUID for the user control.
            string ctlProgID, asmPath, guidStr;
            // Variables for the new tool window that will hold
            // your user control.
            EnvDTE80.Windows2 toolWins;
            EnvDTE.Window toolWin;
            object objTemp = null;
    
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
            ctlProgID = "WindowsControlLibrary2.UserControl1";
            // Replace the <Path to VS Project> with the path to
            // the folder where you created the WindowsCotrolLibrary.
            // Remove the line returns from the path before 
            // running the add-in.
            asmPath = @"c:\My Documents\Visual Studio 2005\Projects\
              WindowsControlLibrary2\WindowsControlLibrary2\bin\
              Debug\WindowsControlLibrary2.dll";
            guidStr = "{E9C60F2B-F01B-4e3e-A551-C09C62E5F584}";
    
            toolWins = (Windows2)_applicationObject.Windows;
            // Create the new tool window, adding your user control.
            toolWin = toolWins.CreateToolWindow2(_addInInstance, 
              asmPath, ctlProgID, "MyNewToolwindow", guidStr, 
              ref objTemp);
            // The tool window must be visible before you do anything 
            // with it, or you will get an error.
            if (toolWins != null)
            {
                toolWin.Visible = true;
            }
            // Set the new tool window's height and width, 
            // and then close it.
            System.Windows.Forms.MessageBox.Show("Setting the height 
            to 500 and width to 400...");
            toolWin.Height = 500;
            toolWin.Width = 400;
            System.Windows.Forms.MessageBox.Show
              ("Closing the tool window...");
            toolWin.Close(vsSaveChanges.vsSaveChangesNo);
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show("Exception: " 
              + ex.Message);
        }
    }
    

    ملاحظةيتطلب التعليمة البرمجية السابقة مرجع إلى System.Windows.Formsمساحة الاسم.

  3. قم بتغيير قيم ctlProgID، asmPath، و guidStrمتغيرات إلى تعكس عنصر تحكم مستخدم الخاص بك.

  4. قم ببناء المشروع وتشغيله.

  5. في القائمة أدوات ، انقر فوق إضافة-في إدارة لتنشيط إضافة-في.

سترى الجديد الخاص بك أداة نافذة عائم في IDE. يمكنك نقله في أي مكان في أو مرسى مع إطارات الأدوات الأخرى.

راجع أيضًا:

المهام

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

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

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

المبادئ

التحكم في إعدادات خيارات

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

موارد أخرى

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

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

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