Jump to content

Prevent selecting text from GUICtrlCreateEdit


Recommended Posts

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 by sandin
Link to comment
Share on other sites

you can use simple UDF and then work with it:

#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 by sandin
Link to comment
Share on other sites

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
:)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...