Results 1 to 2 of 2

Thread: textbox selstart

  1. #1

    Thread Starter
    New Member whynotlynott's Avatar
    Join Date
    Jan 2002
    Location
    Tralee, Co. Kerry, Ireland
    Posts
    14

    textbox selstart

    Hey,

    I've written a subroutine to disable pasting in a textbox, by checking whats just gone into the textbox against what's in the clipboard...

    Private sub txtSuppSurn_Change()
    Call disablepaste(txtSuppSurn)
    End Sub

    And in a module

    Public Sub disablepaste(box As textbox)
    Dim position As Integer

    position = box.SelStart
    If box.SelStart - Len(Clipboard.GetText) >= 0 Then
    box.SelStart = box.SelStart - Len(Clipboard.GetText)
    box.SelLength = Len(Clipboard.GetText)
    If box.SelText = Clipboard.GetText Then box.SelText = "" Else box.SelStart = position
    box.SetFocus
    End If
    End Sub

    Fine, works grand, but i've got a small bonus feature (error) like this: if the lenght of the textbox is above about 8,9 or 10 chars, it looks like the start of the string is chopped off.

    It isn't, the textbox has scrolled along... since this is all supposed to be invisible, that's not good... any ideas? I'd like to keep the processing more or less the same way, so i can selectively disable the pasting etc...

    Cheers

    Des

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I don't know... but try this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub txtSuppSurn_Change()
    4.     DisablePaste txtSuppSurn
    5. End Sub
    6.  
    7. Public Sub DisablePaste(box As TextBox)
    8.     Dim Position As Integer
    9.    
    10.     Position = box.SelStart
    11.     If box.SelStart - Len(Clipboard.GetText) >= 0 Then
    12.         box.SelStart = box.SelStart - Len(Clipboard.GetText)
    13.         box.SelLength = Len(Clipboard.GetText)
    14.         If box.SelText = Clipboard.GetText Then
    15.             If Len(box.Text) > Len(box.Tag) + 1 Then
    16.                 box.SelText = ""
    17.             Else
    18.                 box.SelStart = Len(box.Text)
    19.             End If
    20.         Else
    21.             box.SelStart = Position
    22.         End If
    23.         box.SetFocus
    24.         box.Tag = box.Text
    25.     End If
    26. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width