Results 1 to 8 of 8

Thread: People this is important (I realy need help)

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 1999
    Location
    Vilnius, Lithuania
    Posts
    50

    Post

    I'm having the presentaition of my program tomorow and i noticed that one thing is not finished. I just must finsh it until tomorow. You are my last chance.

    I have 1 textbox

    Problem:

    I need to make program wich disalows user to copy information from textbox to clipboard.
    (I need to make right mouse button and Ctrl+c
    keys inactive on this textbox)

    I tried to make something like:

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    
      If KeyAscii = 2 Then
        KeyAscii = 0
    
          End If
    
    End Sub
    But this just doesn't work


    Any ideas apricieted

    -thank you


    ------------------
    -casparas

    novice programer
    [email protected]

  2. #2
    Addicted Member
    Join Date
    May 1999
    Location
    Californ-I- A
    Posts
    207

    Post

    The way to disable the right click menu is here: http://www.vb-world.net/tips/tip131.html

    As for disabling the ctrl+C and ctrl+x functions, keep in mind that the ctrl key and c key can be pressed at different times so long as the ctrl is pressed first and released last. Try this:

    Option Explicit
    Dim ctrlDown As Boolean
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    'Set ctrlDown to "True" until the KeyUp
    'even is called to release it.
    If Shift = 2 Then ctrlDown = True
    End Sub

    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyC And ctrlDown = True Then
    'User pressed ctrl+C ... clear clipboard
    Clipboard.Clear
    Beep
    End If
    If KeyCode = vbKeyX And ctrlDown = True Then
    'User pressed ctrl+X ... restore text
    'and clear clipboard
    Text1.Text = Clipboard.GetText
    Clipboard.Clear
    Beep
    End If
    'check if ctrl key was released
    If Shift = 2 Then ctrlDown = False
    End Sub


    Good luck!

    ------------------
    Micah Carrick
    http://micah.carrick.com
    [email protected]
    ICQ: 53480225


  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Or you could just set the ENABLED property of the textbox to FALSE, or just use a label instead.

  4. #4
    Hyperactive Member
    Join Date
    Jan 2000
    Posts
    355

    Post

    quite
    just do text1.enabled = false..?

    or subclass it and handle the message manually LOL

    ------------------
    cintel rules
    www.cintelsoftware.co.uk

  5. #5
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Or you could just disable the control key on the keydown event:

    Private Sub Text1_KeyDown(KeyCode as integer)
    'not sure about the constant there... use the help
    if KeyCode = vbKeyControl then KeyCode = 0
    end sub

    To set KeyCode = 0 cancels the key that was pressed....

  6. #6
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    Subclass the textbox, catch the WM_COPY message, and return 1 in the subclass (instead of calling the default windowproc).
    This works pretty fine (I assume, I used it with the WM_PASTE message)
    That's the easiest way.
    The other way ic checking if Ctrl+C is pressed, or Ctrl+Insert is pressed.

  7. #7
    Hyperactive Member venkatraman_r's Avatar
    Join Date
    Jul 1999
    Location
    Chennai, INDIA
    Posts
    284

    Post

    Hi,

    Keep this code in the keypress event of the text box:

    Select Case KeyAscii
    Case 3
    DoEvents
    Clipboard.GetText
    Clipboard.Clear
    MsgBox "You cannot copy items"
    Case 22
    KeyAscii = 0
    End Select

    ------------

    This works well and I hope this is what u need.

    Regards,

    Venkat.

    ------------------
    [email protected]
    ICQ: 45714766
    http://venkat.iscool.net

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 1999
    Location
    Vilnius, Lithuania
    Posts
    50

    Post

    Thank you very much everyone




    ------------------
    -casparas

    novice programer
    [email protected]

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