Jump to content

How to get Cut/Copy/Paste options on a Rich Text field?


qwert
 Share

Recommended Posts

I've tried several style combinations, but haven't been able to activate the standard right-click menu (Cut/Copy/Paste) for a Rich Text Field.  Yet, it's a default feature of normal text fields.  This brief example shows the difference:

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

Local $hGui, $hRichEdit, $iMsg
$hGui = GUICreate("Edit RTF", 320, 240, -1, -1)
$TextInput =  GUICtrlCreateEdit("This is a normal text field.  You can highlight text and right-click to get option to Copy.",  _
20, 20, 240, 60, BitOR ($WS_VSCROLL, $ES_AUTOVSCROLL))
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a rich text field.  You can highlight text ... and CTRL-V works ... but there is no right-click menu.", _
20, 120, 240, 60, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
GUISetState()

While True
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
    EndSelect
WEnd

Can anyone shed light on this?  What rules govern right-click menus? 

(CreateMenu, of course, can add an edit menu for the entire window ... and those features work for both text types.  But I'm working with a frameless GUI without a menu bar.)

Thanks in advance for any help.

 

Link to comment
Share on other sites

  • Moderators

qwert,

Edit and Input (which is just a forced single-line Edit) controls have system context menus - that is what you are seeing when you right click and why the Help file for GUICtrlCreateContextMenu tells you that you cannot use it on that type of control. ;)

For a RichEdit control, you need to create your own context menu - and a quick search of the forum (the box is at top right) brought up this thread as the first hit, which works very nicely. :)

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

Thanks, Melba23.  "context menu" was the term I was missing.  I had searched for "right-click" and "cut", "copy", etc., ... without hitting the right track.

The menu is now coming up for the Rich Text field and the three actions seem to work ... but the cursor pointer isn't always reset to an arrow.  So I think I might not have the Case statements quite right.  Is there a better way than what I have?:

Case $WM_COMMAND
         Switch $wParam
             Case $idCut
                  Send("^x")
             Case $idCopy
                  Send("^c")
             Case $idPaste
                  Send("^v")
    EndSwitch

Thanks for any advice.

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