igorm Posted June 9, 2008 Posted June 9, 2008 Hi, Is there some way that I can prevent selecting text using mouse or keyboard from GUICtrlCreateEdit? I'm using GUICtrlCreateEdit for displaying some informations but I want to prevent selecting and copying the text from it. Cheers Office 2000/XP/2003/2007 Slipstreamer
sandin Posted June 9, 2008 Posted June 9, 2008 (edited) use label instead, and if you wanna "edit's" look, square the label with GUICtrlCreateGraphic() #include <GUIConstants.au3> #include <EditConstants.au3> $Form1 = GUICreate("Form1", 150, 120) $Label1 = GUICtrlCreateLabel("Some text goes here", 20, 20, 100, 17) $rect = GUICtrlCreateGraphic(15, 18, 124, 20) GUICtrlSetColor(-1, 0x00A7A6AA) $edit1 = GUICtrlCreateEdit("Some text goes here", 15, 50, 120, 20, $ES_READONLY) GUISetState(@SW_SHOW) While 1 if GUIGetMsg()= $GUI_EVENT_CLOSE then Exit WEnd Edited June 9, 2008 by sandin Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll
k3v Posted June 9, 2008 Posted June 9, 2008 You could also use: GUICtrlSetState($myEdit,$GUI_DISABLE) and to retain the white background... GUICtrlSetBkColor($myEdit,0xfcfcfc) (it's been my experience that the text will always be gray, however, even if you try to apply a foreground color to it)
igorm Posted June 9, 2008 Author Posted June 9, 2008 use label instead, and if you wanna "edit's" look, square the label with GUICtrlCreateGraphic() #include <GUIConstants.au3> #include <EditConstants.au3> $Form1 = GUICreate("Form1", 150, 120) $Label1 = GUICtrlCreateLabel("Some text goes here", 20, 20, 100, 17) $rect = GUICtrlCreateGraphic(15, 18, 124, 20) GUICtrlSetColor(-1, 0x00A7A6AA) $edit1 = GUICtrlCreateEdit("Some text goes here", 15, 50, 120, 20, $ES_READONLY) GUISetState(@SW_SHOW) While 1 if GUIGetMsg()= $GUI_EVENT_CLOSE then Exit WEnd This is good idea, but is seems that I can't figure how to put new text without overwriting the old. Is that possible with GUICtrlCreateLabel() ? You could also use: GUICtrlSetState($myEdit,$GUI_DISABLE) and to retain the white background... GUICtrlSetBkColor($myEdit,0xfcfcfc) (it's been my experience that the text will always be gray, however, even if you try to apply a foreground color to it) That was my first idea, but I just don't like the gray text. But thanks anyway. Cheers Office 2000/XP/2003/2007 Slipstreamer
sandin Posted June 9, 2008 Posted June 9, 2008 (edited) This is good idea, but is seems that I can't figure how to put new text without overwriting the old. Is that possible with GUICtrlCreateLabel() ?#include <GUIConstants.au3> #include <EditConstants.au3> $Form1 = GUICreate("Form1", 150, 120) $Label1 = GUICtrlCreateLabel("Some text goes here", 20, 20, 100, 57) GUICtrlSetBkColor(-1, 0xfcfcfc) $rect = GUICtrlCreateGraphic(15, 18, 110, 60) GUICtrlSetBkColor(-1, 0xfcfcfc) GUICtrlSetColor(-1, 0x00A7A6AA) $button1 = GUICtrlCreateButton("Add more text", 30, 90, 80) GUISetState(@SW_SHOW) dim $i = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button1 $i += 1 GUICtrlSetData($Label1, GUICtrlRead($Label1) & @CRLF & "some more text " & $i) EndSwitch WEnd Edited June 9, 2008 by sandin Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll
sandin Posted June 9, 2008 Posted June 9, 2008 (edited) you can use simple UDF and then work with it: expandcollapse popup#include <GUIConstants.au3> #include <EditConstants.au3> $Form1 = GUICreate("Form1", 150, 120) $Label = _UnSelectable_Iinput("Some text goes here", 10, 10, 105, 40) $button1 = GUICtrlCreateButton("add text", 10, 90, 60) GUISetState(@SW_SHOW) dim $i = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button1 $curent_text = guictrlread($Label) GUICtrlSetData($Label, $curent_text & " more text") EndSwitch WEnd ;=============================================================================== ; ; Function Name: _UnSelectable_Iinput() ; ; Function Description: Creates an input looking label which is unselectable. ; (no copy/paste is posible) ; ; Parameter(s): $text - text in control ; $left - left coordinate of the control in your GUI ; $top - top coordinate of the control in your GUI ; $width - width of your control ; $height - height of your control ; $color [Optional] - text's color ; $bk_color [Optional] - background of the control ; $rec_Color [Optional] - color of the input's "box" ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return control over the control's text ; ;===================================================================== func _UnSelectable_Iinput($text, $left, $top, $width, $height, $color = 0, $bk_color = 0xfcfcfc, $rec_Color = 0x00A7A6AA) local $_UnSelectable_Input_Label $_UnSelectable_Input_Label = GUICtrlCreateLabel($text, $left+3, $top+1, $width-4, $height-2) GUICtrlSetColor(-1, $color) GUICtrlSetBkColor(-1, $bk_color) GUICtrlCreateGraphic($left, $top, $width, $height) GUICtrlSetColor(-1, $rec_Color) GUICtrlSetBkColor(-1, $bk_color) return $_UnSelectable_Input_Label EndFunc Edited June 9, 2008 by sandin Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll
igorm Posted June 9, 2008 Author Posted June 9, 2008 (edited) Thanks, nice UDF. Cheers Edited June 9, 2008 by igorm Office 2000/XP/2003/2007 Slipstreamer
rasim Posted June 10, 2008 Posted June 10, 2008 Another way: #include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <GuiEdit.au3> $hGUI = GUICreate("Test GUI", 300, 200) $edit = GUICtrlCreateEdit("Hello world!", 10, 10, 280, 180) GUISetState() Do $aSel = _GUICtrlEdit_GetSel($edit) If ($aSel[0] <> 0) Or ($aSel[1] <> 0) Then _GUICtrlEdit_SetSel($edit, 0, 0) Until GUIGetMsg() = $GUI_EVENT_CLOSE
igorm Posted June 10, 2008 Author Posted June 10, 2008 This one is nice. Is there a way I can keep pointer and the end of the text? Cheers Office 2000/XP/2003/2007 Slipstreamer
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now