Page 1 of 1

A simple Addin How to create a simple addin in vb.net Rate Topic: -----

#1 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • View blog
  • Posts: 1,600
  • Joined: 17-April 07

Posted 27 February 2010 - 02:31 AM

hi to all
i am going to create a simple add-in for Regionizing a procedure or a Function

just follow the steps to cerate a Addin

1. Click the new Project on the File Menu
2. now Select the other projects type on that Select Extensibileity
3. now select the Addin for Visual studio
4. now a wizard raises Follow the Wizard
5. On the First page of the Wizard Select the language you familiar
6. And on the third page give a name to your Addin
7. on the Fourth page select the top to checkboxes if necessary (if you read it you can understand it)
8. now just follow to the final step
9. that's all you create a simple addin

now it's time to some simple coding just follow the link i provide

TextSelection is an object used to find what text currently selected in the IDE of the Code Editor

CodeClass is used to Find what class is available in your DTE Currently

To me CodeElementis the best object to get all kind of Coding Structures here

using Code Element you can get all the information available in your Code window,
there are various Code Elements
using this you can find the name of all Classes, functions ,variables,procedures , etc..

_applicationObject is the Currently Run Instance of a VS

_addInInstance is the Currently Running instance of a Addin

using this things i have Found a simple start up here
Sub ShowElems()
                Try
                        Dim objTextSel As TextSelection
                        Dim objCodeCls As CodeClass
                        objTextSel = CType(DTE.Activedocument.Selection, TextSelection)
                        objCodeCls = CType(objTextSel.ActivePoint.CodeElement(vsCMElement.vsCMElementClass), CodeClass)
                        ' Add comments to CodeClass objCodeClass - notice change in code document.
                        objCodeCls.Comment = "Comments for the CodeClass object."
                        ' Access top-level object through the CodeClass object
                        ' and return the file name of that top-level object.

                        System.Windows.Forms.MessageBox.Show("Top-level object's filename: " + objCodeCls.DTE.FileName)
                        ' Get the language used to code the CodeClass object - returns a GUID.
                        System.Windows.Forms.MessageBox.Show(objCodeCls.Language)
                        ' Get a collection of elements contained by the CodeClass object.
                        Dim members As String = "Member Elements of " + objCodeCls.Name + ": " + vbCrLf

                        For Each elem As CodeElement In objCodeCls.Members
                                members = members + (elem.Name + vbCrLf)
                        Next elem
                        System.Windows.Forms.MessageBox.Show(members)
                Catch ex As Exception
                        System.Windows.Forms.MessageBox.Show(ex.Message)
                End Try
End Sub





call this sub in the Exec Sub now run the Addin

now there is a new vs instance is opened for you you can find your add in in the tools menu directly

now open a project and select a code editor window

now click on your addin

your have find some messageboxes

did you notice that the code elements are shown in your messsagebox
now
That's all you done it for more reading here"]just use this link[/url]

From this i try to Regionize a code structure for some days

and finally i got this

Sun Regionize()
                        objTextSel.MoveToPoint(objcodeElem.StartPoint, False)
                        objTextSel.LineDown(True, (objcodeElem.GetEndPoint.Line - objcodeElem.GetStartPoint.Line) + 1)
                        Dim st As String = objTextSel.Text
                        st = "#Region """ & objcodeElem.Name & """" + vbNewLine + st + vbNewLine
                        st += "#End Region"
                        objTextSel.Text = ""
                        objTextSel.Insert(st)
End Sub



hope this is a start up to create a addin


Is This A Good Question/Topic? 0
  • +

Replies To: A simple Addin

#2 Vermiculus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 314
  • Joined: 26-February 09

Posted 25 March 2010 - 07:59 PM

This tutorial may need proofreading...
Otherwise a very informative tutorial. :)

This post has been edited by Vermiculus: 25 March 2010 - 08:00 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1