Prevent/disable text selection in Edit control?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Prevent/disable text selection in Edit control?

Post by TheDewd » 22 Jun 2018, 11:03

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!

imustbeamoron
Posts: 44
Joined: 18 Aug 2016, 22:56

Re: Prevent/disable text selection in Edit control?

Post by imustbeamoron » 22 Jun 2018, 11:20

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

User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Prevent/disable text selection in Edit control?

Post by TheDewd » 22 Jun 2018, 11:27

imustbeamoron wrote:maybe just use disabled ?
Disabling an edit control will change its appearance which I don't want.

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

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Prevent/disable text selection in Edit control?

Post by jeeswg » 22 Jun 2018, 11:37

- 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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Prevent/disable text selection in Edit control?

Post by wolf_II » 22 Jun 2018, 11:40

Maybe use the sendmessage, but replace the SetTimer with a gLabel?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Prevent/disable text selection in Edit control?

Post by swagfag » 22 Jun 2018, 12:38

Place a dummy hidden button. Monitor the edit control for gain of focus, then redirect focus to the dummy button.

imustbeamoron
Posts: 44
Joined: 18 Aug 2016, 22:56

Re: Prevent/disable text selection in Edit control?

Post by imustbeamoron » 22 Jun 2018, 12:51

alot of hackish ways to do it i guess.
i would agree with jeeswg though and use a static control.

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Prevent/disable text selection in Edit control?

Post by burque505 » 22 Jun 2018, 14:28

Another hack ---

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
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
Last edited by burque505 on 22 Jun 2018, 14:58, edited 2 times in total.

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Prevent/disable text selection in Edit control?

Post by wolf_II » 22 Jun 2018, 14:57

besides the point that my idea was futile, I like burque505 best! Thx for sharing, it's brilliant. :thumbup:

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: Prevent/disable text selection in Edit control?

Post by burque505 » 22 Jun 2018, 14:59

Thanks, wolf_II. I'm the kind of guy who uses a screwdriver as a hammer, may have something to do with it :)

Post Reply

Return to “Ask for Help (v1)”