Results 1 to 31 of 31

Thread: Text Box

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32

    Text Box

    In VB6 is there a way to set a textbox so that it can't be manipulated in any way? i.e Can't edit, can't select text, can't paste text, no caret visible at any time, ect...I am using a textbox because I need have a multiline control that has scrollbars if the text fills more than the textbox area...Maybe there is another control I could use for this

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    .enabled = false

    or .locked = true

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Lock propert (but you want be able to use the scrollbars)

    What kinda of data will you be displaying?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32

    Unhappy

    I will be displaying a field from an access DB...I don't want to use the locked option cause it changes the text color

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Rich Text Box control ?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32

    No luck

    I tried the RichTextBox but I can't get it to do all those things I want it too...If I lock it you can still see the caret, and select the text...Any other suggestions??

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Extreme approach. Write out the text to a picturebox control and add your own scrollbars, if necessary...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Put the textbox inside a frame and disable the frame.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    because I need have a multiline control that has scrollbars if the text fills more than the textbox area
    crptcblade : Your way the scrollbars would be disabled too...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  10. #10
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    in the keydown put keyascii = 0
    in a timer, text1.sellength = 0

    try that.

  11. #11
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Meh. That's what you get for not reading the whole thread.

    You could set the Locked property to True, and use the HideCaret API to remove the caret.

    VB Code:
    1. Private Declare Function HideCaret Lib "user32" Alias "HideCaret" (ByVal hwnd As Long) As Long

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  12. #12
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    But blade, the scrollbars?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  13. #13
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Locked disables the scrollbars?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  14. #14
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by crptcblade
    Locked disables the scrollbars?
    I believe it does, or I will look like the ass...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  15. #15
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Just tried, and they still work for me.








    Ass.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  16. #16
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by crptcblade
    Just tried, and they still work for me.



    Exiting the thread, embarrassed...

    Signed the ass...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  17. #17

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32
    yes but if I lock the textbox I can still select the text and the hide caret doesn't work very well

  18. #18
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    make a timer

    put in it:

    if text.sellength > 0 then text.sellength = 0

  19. #19
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    If you want to go all out, you could subclass the textbox to disallow the mouse to do anything while its locked. I can give you an example if you want to try.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  20. #20

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32

    Example

    I would really appreciate an example of that subclass Blade

  21. #21
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. '***********************
    2. ' In Your Form
    3. '***********************
    4.  
    5.  
    6. Option Explicit
    7.  
    8. Private Sub Command1_Click()
    9.     Text1.Locked = Not Text1.Locked
    10. End Sub
    11.  
    12. Private Sub Form_Load()
    13.     Call Hook(Text1.hwnd)
    14. End Sub
    15.  
    16. Private Sub Form_Unload(Cancel As Integer)
    17.     Call Unhook(Text1.hwnd)
    18. End Sub
    19.  
    20.  
    21. '***********************
    22. ' In a Standard Module
    23. '***********************
    24.  
    25. Option Explicit
    26.  
    27. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
    28.                                                                              ByVal hwnd As Long, _
    29.                                                                              ByVal Msg As Long, _
    30.                                                                              ByVal wParam As Long, _
    31.                                                                              ByVal lParam As Long) _
    32.                                                                              As Long
    33. Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, _
    34.                                                                            ByVal wMsg As Long, _
    35.                                                                            ByVal wParam As Long, _
    36.                                                                            ByVal lParam As Long) _
    37.                                                                            As Long
    38. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, _
    39.                                                                            ByVal nIndex As Long, _
    40.                                                                            ByVal dwNewLong As Long) _
    41.                                                                            As Long
    42. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, _
    43.                                                                            ByVal nIndex As Long) _
    44.                                                                            As Long
    45.  
    46. Public Const GWL_WNDPROC = (-4)
    47. Public Const GWL_STYLE = (-16)
    48.  
    49. Public Const WM_LBUTTONUP = &H202
    50. Public Const WM_RBUTTONUP = &H205
    51. Public Const WM_LBUTTONDOWN = &H201
    52. Public Const WM_RBUTTONDOWN = &H204
    53.  
    54. Public Const ES_READONLY = &H800&
    55.  
    56. Private mPrevProc As Long
    57.  
    58. Public Function TextBoxProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    59. On Error Resume Next
    60.  
    61.     If GetWindowLong(hwnd, GWL_STYLE) And ES_READONLY Then 'If the textbox is locked
    62.         Select Case uMsg
    63.             Case WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP
    64.                 TextBoxProc = 0
    65.                 Exit Function
    66.         End Select
    67.     End If
    68.  
    69.     If mPrevProc = 0 Then
    70.         TextBoxProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
    71.     Else
    72.         TextBoxProc = CallWindowProc(mPrevProc, hwnd, uMsg, wParam, lParam)
    73.     End If
    74.  
    75. End Function
    76.  
    77. Public Sub Hook(hwnd As Long)
    78.     mPrevProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf TextBoxProc)
    79. End Sub
    80.  
    81. Public Sub Unhook(hwnd As Long)
    82.    
    83.     Call SetWindowLong(hwnd, GWL_WNDPROC, mPrevProc)
    84.     mPrevProc = 0&
    85.    
    86. End Sub

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  22. #22

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32

    Thank You

    Thanx for that example Blade...It works exactly how I want it to...Now I'll have to go through it and dipher what you did so I know for next time...Once again, thanx to all who posted to this thread

  23. #23

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32

    Opps

    There is a problem with that...If you Double-Click the textbox, the prog freezes and you can't do anything

  24. #24
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I just noticed that too. I have no idea why it happens, but I'll try to see if I can figure it out.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  25. #25
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Okay, I think I got it. Its because the WindowProc was handling messages for all the mouse states. In other words, the line that looks like...
    VB Code:
    1. Case WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP

    should only look like...
    VB Code:
    1. Case WM_LBUTTONDOWN, WM_RBUTTONDOWN

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  26. #26

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32

    I think your right

    I was going through step by step and noticed that too...I was about to change it and VB took a dumb...Going to try it now

  27. #27
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: I think your right

    Originally posted by Snoopy23
    I was going through step by step and noticed that too...I was about to change it and VB took a dumb...Going to try it now
    Its important to know that you can't really debug subclassing code too well during run-time. I think MS has a DLL that helps to let you do so, but I don't know where to find it.

    Also, hitting the stop button while running subclassing is nor a good idea, either. I've take a few steps to prevent VB from crashing if you do hit stop, but there is no guarantee.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  28. #28

    Thread Starter
    Member
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    32

    It works now

    I had originally put a stop point at the end of the modules so I could go in and see all the values being used and that's how I noticed the Case WM_LBUTTONDOWN statement was doing something wrong...Anyways, thanks for your help...I tried it out and I can't get it to crash so all is well

  29. #29
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: It works now

    Originally posted by Snoopy23
    I tried it out and I can't get it to crash so all is well
    Its always a good sign when you can't get it to not work. And if you have questions on what the subclassing code is doing, don't be afraid to ask.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  30. #30
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Originally posted by crptcblade
    Locked disables the scrollbars?
    They don't.
    Luke

  31. #31
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Originally posted by macai
    They don't.
    How helpful.

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