Jump to content
Sign in to follow this  
amin84

Copy, Cut, Paste, Select All from GUICtrlEdit

Recommended Posts

I searched for a while and I couldn't find much on this so here it is. This is used when you have the Edit menu with all of these in it. The problem with sending Ctrl+C or Ctrl+V is that you will loose the selection. This code will work with selection too. In this example the GUICtrlEdi is called $Edit1 and to use them you just assign the function to the button or menu...

Func _selectAll()
        _GUICtrlEdit_SetSel($Edit1,0,-1)
EndFunc
Func _cut()
        $range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1))
        If $range[0] <> $range[1] Then
                ClipPut(StringMid(GUICtrlRead($Edit1), $range[0] + 1, $range[1] - $range[0]))
        EndIf
        _GUICtrlEdit_ReplaceSel(GUICtrlGetHandle($Edit1),'')
EndFunc
Func _copy()
        $range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1))
        If $range[0] <> $range[1] Then
                ClipPut(StringMid(GUICtrlRead($Edit1), $range[0] + 1, $range[1] - $range[0]))
        EndIf
EndFunc
Func _paste()
        $range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1))
        _GUICtrlEdit_ReplaceSel(GUICtrlGetHandle($Edit1),'')
        _GUICtrlEdit_InsertText($Edit1,ClipGet(),$range[0])
EndFunc
Edited by leomoon

Share this post


Link to post
Share on other sites

I don't loose selection after pressing Ctrl+C. Ctrl+A doesn't seem to work for me (and several others), so I have always created an accel key to handle that. You will always loose selected text after a paste action anyway. So do you have a question?

Edit

I agree that it is a good idea to write the code rather than relying on the Send function.

Edited by czardas

Share this post


Link to post
Share on other sites

No I was just sharing the code I got. I added Cut, Copy and Paste as a menu (hotkeys work fine) but in order to get that menu working (not using keyboard) I had to either set the GUICtrlEdit as active then send ctrl+c or do it this way. If you use the first method, by the time we set it as active, it will loose the selection if the user had any. So I wrote this instead of setting active and sending hotkeys... Cuz lets say the user has selected a portion and wants to paste (replace) the selected with clipboard...

That Ctrl+A only works if you only have one Edit box which I do (called $Edit1)...

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...