|
-
Oct 5th, 2002, 07:26 PM
#1
Thread Starter
Member
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
-
Oct 5th, 2002, 07:27 PM
#2
So Unbanned
.enabled = false
or .locked = true
-
Oct 5th, 2002, 07:28 PM
#3
PowerPoster
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....
-
Oct 5th, 2002, 07:40 PM
#4
Thread Starter
Member
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
-
Oct 5th, 2002, 07:41 PM
#5
PowerPoster
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 5th, 2002, 07:49 PM
#6
Thread Starter
Member
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??
-
Oct 5th, 2002, 07:51 PM
#7
PowerPoster
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....
-
Oct 5th, 2002, 07:54 PM
#8
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
-
Oct 5th, 2002, 07:55 PM
#9
PowerPoster
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....
-
Oct 5th, 2002, 07:57 PM
#10
So Unbanned
in the keydown put keyascii = 0
in a timer, text1.sellength = 0
try that.
-
Oct 5th, 2002, 07:57 PM
#11
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:
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
-
Oct 5th, 2002, 07:59 PM
#12
PowerPoster
Well
But blade, the scrollbars?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 5th, 2002, 08:00 PM
#13
Locked disables the scrollbars?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 5th, 2002, 08:00 PM
#14
PowerPoster
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....
-
Oct 5th, 2002, 08:01 PM
#15
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
-
Oct 5th, 2002, 08:03 PM
#16
PowerPoster
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 5th, 2002, 08:08 PM
#17
Thread Starter
Member
yes but if I lock the textbox I can still select the text and the hide caret doesn't work very well
-
Oct 5th, 2002, 08:09 PM
#18
So Unbanned
make a timer
put in it:
if text.sellength > 0 then text.sellength = 0
-
Oct 5th, 2002, 08:26 PM
#19
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
-
Oct 5th, 2002, 08:30 PM
#20
Thread Starter
Member
Example
I would really appreciate an example of that subclass Blade
-
Oct 5th, 2002, 08:37 PM
#21
VB Code:
'***********************
' In Your Form
'***********************
Option Explicit
Private Sub Command1_Click()
Text1.Locked = Not Text1.Locked
End Sub
Private Sub Form_Load()
Call Hook(Text1.hwnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call Unhook(Text1.hwnd)
End Sub
'***********************
' In a Standard Module
'***********************
Option Explicit
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) _
As Long
Public Const GWL_WNDPROC = (-4)
Public Const GWL_STYLE = (-16)
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONUP = &H205
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_RBUTTONDOWN = &H204
Public Const ES_READONLY = &H800&
Private mPrevProc As Long
Public Function TextBoxProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next
If GetWindowLong(hwnd, GWL_STYLE) And ES_READONLY Then 'If the textbox is locked
Select Case uMsg
Case WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP
TextBoxProc = 0
Exit Function
End Select
End If
If mPrevProc = 0 Then
TextBoxProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
Else
TextBoxProc = CallWindowProc(mPrevProc, hwnd, uMsg, wParam, lParam)
End If
End Function
Public Sub Hook(hwnd As Long)
mPrevProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf TextBoxProc)
End Sub
Public Sub Unhook(hwnd As Long)
Call SetWindowLong(hwnd, GWL_WNDPROC, mPrevProc)
mPrevProc = 0&
End Sub
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 5th, 2002, 08:50 PM
#22
Thread Starter
Member
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
-
Oct 5th, 2002, 08:58 PM
#23
Thread Starter
Member
Opps
There is a problem with that...If you Double-Click the textbox, the prog freezes and you can't do anything
-
Oct 5th, 2002, 09:28 PM
#24
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
-
Oct 5th, 2002, 09:32 PM
#25
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:
Case WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP
should only look like...
VB Code:
Case WM_LBUTTONDOWN, WM_RBUTTONDOWN
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 5th, 2002, 09:34 PM
#26
Thread Starter
Member
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
-
Oct 5th, 2002, 09:38 PM
#27
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
-
Oct 5th, 2002, 09:43 PM
#28
Thread Starter
Member
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
-
Oct 5th, 2002, 09:44 PM
#29
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
-
Oct 6th, 2002, 03:07 AM
#30
Frenzied Member
Originally posted by crptcblade
Locked disables the scrollbars?
They don't.
-
Oct 6th, 2002, 03:10 AM
#31
So Unbanned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|