For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Addins > September 2005 > write at cursor position









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author write at cursor position
luis

2005-09-13, 7:02 pm

How can i write a Text at the cursor position from my addin?. I find methods
to write in declaration zone, obtain line of proc begin, ... but i don´t
known how obtain the actual line in the code module.



Peter Macej

2005-09-14, 3:58 am

Use Selection property to get current cursor position:

Dim selection As TextSelection
Dim cursor As EditPoint

selection = dte.ActiveDocument.Selection
cursor = selection.ActivePoint.CreateEditPoint
cursor.Insert("my text")


--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Peter Macej

2005-09-14, 7:58 am

Ooops, sorry. I gave you the VS .NET solution. You probably need VB6
solution:

Dim x1 As Long
Dim y1 As Long
Dim x2 As Long
Dim y2 As Long
Dim cmo As VBIDE.CodeModule

' get cursor (into x1, y1, x2, y2)
VBInstance.ActiveCodePane.GetSelection x1, y1, x2, y2
' if selection
If x1 <> x2 Or y1 <> y2 Then
MsgBox "This is selection, not single cursor"
Exit Sub
End If
' get code module
Set cmo = VBInstance.ActiveCodePane.CodeModule
' insert text
cmo.InsertLines x1, "My text"

I copied parts of our code and I didn't test it but it should work.

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code



Peter Macej wrote:
> Use Selection property to get current cursor position:
>
> Dim selection As TextSelection
> Dim cursor As EditPoint
>
> selection = dte.ActiveDocument.Selection
> cursor = selection.ActivePoint.CreateEditPoint
> cursor.Insert("my text")
>
>

luis

2005-09-15, 7:02 pm

Thanks

"Peter Macej" <peter@vbdocman.com> escribió en el mensaje
news:uum1OeSuFHA.2008@TK2MSFTNGP10.phx.gbl...[color=darkred]
> Ooops, sorry. I gave you the VS .NET solution. You probably need VB6
> solution:
>
> Dim x1 As Long
> Dim y1 As Long
> Dim x2 As Long
> Dim y2 As Long
> Dim cmo As VBIDE.CodeModule
>
> ' get cursor (into x1, y1, x2, y2)
> VBInstance.ActiveCodePane.GetSelection x1, y1, x2, y2
> ' if selection
> If x1 <> x2 Or y1 <> y2 Then
> MsgBox "This is selection, not single cursor"
> Exit Sub
> End If
> ' get code module
> Set cmo = VBInstance.ActiveCodePane.CodeModule
> ' insert text
> cmo.InsertLines x1, "My text"
>
> I copied parts of our code and I didn't test it but it should work.
>
> --
> Peter Macej
> Helixoft - http://www.vbdocman.com
> VBdocman - Automatic generator of technical documentation for VB, VB
> .NET and ASP .NET code
>
>
>
> Peter Macej wrote:


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com