Is it possible to prevent a user from selecting the text (highlighting) in a ReadOnly edit control?
I'm having trouble finding an answer. It seems that most people want to select text -- not prevent selection.
Any ideas? Thanks!
Prevent/disable text selection in Edit control?
-
- Posts: 44
- Joined: 18 Aug 2016, 22:56
Re: Prevent/disable text selection in Edit control?
maybe just use disabled ? if its read only, and you dont want them selecting text, it seems to fit the bill.
Code: Select all
gui, add, edit, Disabled, Some random text
Re: Prevent/disable text selection in Edit control?
Disabling an edit control will change its appearance which I don't want.imustbeamoron wrote:maybe just use disabled ?
The edit is ReadOnly, but I've customized the background color and text color to look like a normal edit control. I'm not sure how I would make a disabled control look normal.
One option I've considered is using a timer to automatically deselect text, but I want to see if there is a better solution.
Code: Select all
SetTimer, Timer1, 1
Timer1:
SendMessage, 0xB1, -1, -1,, ahk_id %hOutput%
return
Re: Prevent/disable text selection in Edit control?
- If you use a Static control ('Text' control in AHK), is that sufficient?
- Could you explain exactly what you want to achieve?
- Or do you want the caret to appear, and to be able to navigate through the control via caret/scrollbars?
- You could monitor WM_KEYDOWN (check for shift down and return 0 for certain keys) and perhaps do something similar for some of the click messages e.g. WM_LBUTTONDOWN and WM_LBUTTONDBLCLK.
- Could you explain exactly what you want to achieve?
- Or do you want the caret to appear, and to be able to navigate through the control via caret/scrollbars?
- You could monitor WM_KEYDOWN (check for shift down and return 0 for certain keys) and perhaps do something similar for some of the click messages e.g. WM_LBUTTONDOWN and WM_LBUTTONDBLCLK.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Prevent/disable text selection in Edit control?
Maybe use the sendmessage, but replace the SetTimer with a gLabel?
Re: Prevent/disable text selection in Edit control?
Place a dummy hidden button. Monitor the edit control for gain of focus, then redirect focus to the dummy button.
-
- Posts: 44
- Joined: 18 Aug 2016, 22:56
Re: Prevent/disable text selection in Edit control?
alot of hackish ways to do it i guess.
i would agree with jeeswg though and use a static control.
i would agree with jeeswg though and use a static control.
Re: Prevent/disable text selection in Edit control?
Another hack ---
All the clicks fall through to the edit behind
EDIT: Well now, that's a fine kettle of fish. I spoke too soon, as the edit below can be edited. Fixed
Regards,
burque505
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Gui, New
Gui, Add, Edit, x10 y10 w400 h400 +ReadOnly ;added ReadOnly after the Edit
Gui, Add, Edit, x10 y10 w400 h400 +Readonly +Transparent, Try to select me
Gui, Show
return
Escape::ExitApp
EDIT: Well now, that's a fine kettle of fish. I spoke too soon, as the edit below can be edited. Fixed
Regards,
burque505
Last edited by burque505 on 22 Jun 2018, 14:58, edited 2 times in total.
Re: Prevent/disable text selection in Edit control?
besides the point that my idea was futile, I like burque505 best! Thx for sharing, it's brilliant.
Re: Prevent/disable text selection in Edit control?
Thanks, wolf_II. I'm the kind of guy who uses a screwdriver as a hammer, may have something to do with it