Jump to content

How to delete 1 word in guictrlcreateinput? Do not use the Backspace and guictrlsetdata keys ($ Ctr, "Delet"), is there any othe - (Moved)


 Share

Recommended Posts

code: 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$GuiM = GUICreate("Example", 300, 129, 411, 115)
$Input_String = GUICtrlCreateInput("Delete", 48, 16, 193, 21)
$Button_Delete = GUICtrlCreateButton("Delete", 80, 56, 129, 41)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
 

 

 

Untitled.png

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I mean, in the input there are any texts I want the line of delete button in the gui that I mentioned to delete a word like Backspace but it deleted with that button :(. I'm sorry for not using guictrlsetdata

Link to comment
Share on other sites

I do not understand the answer you just gave, but if you are looking at more flexibility, you could use GuiEdit.au3 UDF.  There is a lot of functions that will help you manipulate the control (e.g. _GUICtrlEdit_ReplaceSel)

Edited by Nine
Link to comment
Share on other sites

  • Moderators

Loc,

Is it possible you are looking for a "cue banner" that only appears when the input does not have focus?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

$GuiM = GUICreate("Example", 300, 129, 411, 115)
$Input_String = GUICtrlCreateInput("", 48, 16, 193, 21)
_GUICtrlEdit_SetCueBanner ($Input_String, "Delete")
$Button_Delete = GUICtrlCreateButton("Delete", 80, 56, 129, 41)
GUICtrlSetState($Button_Delete, $GUI_FOCUS)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Loc,

So how about this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$GuiM = GUICreate("Example", 300, 129, 411, 115)
$Input_String = GUICtrlCreateInput("Word_1 Word_2 Word_3", 48, 16, 193, 21)
$Button_Delete = GUICtrlCreateButton("Delete", 80, 56, 129, 41)
GUICtrlSetState($Button_Delete, $GUI_FOCUS)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_Delete
            ; Read input content
            $sContent = GUICtrlRead($Input_String)
            ; Look for right-most space
            $iIndex = StringInStr($sContent, " ", 0, -1)
            If $iIndex Then
                ; Strip final word
                GUICtrlSetData($Input_String, StringMid($sContent, 1, $iIndex - 1))
            Else
                ; Only one word so empty input
                GUICtrlSetData($Input_String, "")
            EndIf
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Or maybe this ?

#include <GUIConstants.au3>
#include <GuiEdit.au3>
#include <Constants.au3>

Global Const $WordToBeDeleted = "Test"

Local $hGUI = GUICreate("Example", 300, 129, 411, 115)
Local $Input_String = GUICtrlCreateInput("Word_1 Test Word_2", 48, 16, 193, 22)
Local $Button_Delete = GUICtrlCreateButton("Delete", 80, 56, 129, 25)
GUICtrlSetState($Button_Delete, $GUI_FOCUS)
GUISetState()

Local $sContent, $iIndex

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
    Case $Button_Delete
      ; Read input content
      $sContent = _GUICtrlEdit_GetText ($Input_String)
      ; Look for first occurence
      $iIndex = StringInStr($sContent, $WordToBeDeleted)
      If $iIndex Then
        ; Strip word with a backspace
        GUICtrlSetState($Input_String, $GUI_FOCUS)
        _GUICtrlEdit_SetSel ($Input_String, $iIndex-1, $iIndex+StringLen($WordToBeDeleted)-1)
        Send ("{BS}")
      EndIf
  EndSwitch
WEnd

 

Link to comment
Share on other sites

Another way:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$GuiM = GUICreate("Example", 300, 129, 411, 115)
$Input_String = GUICtrlCreateInput("Word_1 Word_2 Word_3", 48, 16, 193, 21)
$Button_Delete = GUICtrlCreateButton("Delete", 80, 56, 129, 41)
GUICtrlSetState($Button_Delete, $GUI_FOCUS)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_Delete
            GUICtrlSetData($Input_String, StringRegExpReplace(GUICtrlRead($Input_String), "(.*)\b\h?\S+", "$1"))
    EndSwitch
WEnd

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Following @Nine's example, you could also use 

_GUICtrlEdit_ReplaceSel($Input_String, "")

or ControlSend instead of 

Send ("{BS}")

 

Sightly more elegant and error proof in my opinion.

Link to comment
Share on other sites

Loc what exactly do you want to achieve, could you show us an example of the content of the input box before and after clicking the button ?

Is is the last word you want to erase ? Or like I was thinking a specific word somewhere inside the box ?

Do you want the caret be located in the input box at the deletion location ? 

An example would greatly help us understand your goals 

Edited by Nine
Link to comment
Share on other sites

Maybe you mean to delete a char from left side ? Or from the right side ? Here are both examples

#include <GUIConstantsEx.au3>


$GuiM = GUICreate("Example", 300, 129, 411, 115)
$Input_String = GUICtrlCreateInput("Delete me test tset em eteleD", 48, 16, 193, 21)
$Button_Delete = GUICtrlCreateButton("Delete", 80, 46, 129, 25)
$Button_BS = GUICtrlCreateButton("Backspace", 80, 76, 129, 25)
GUICtrlSetState($Button_Delete, $GUI_FOCUS)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_Delete
            $tmp=GUICtrlRead($Input_String)
            $tmp=StringRight($tmp, StringLen($tmp)-1)
            GUICtrlSetData($Input_String, $tmp)
        Case $Button_BS
            $tmp=GUICtrlRead($Input_String)
            $tmp=StringLeft($tmp, StringLen($tmp)-1)
            GUICtrlSetData($Input_String, $tmp)
    EndSwitch
WEnd

 

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Mostly by chance I suppose, since you never took the pain to explain yourself completely, nor answer the several questions that were posed.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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...