Board index » cppbuilder » Synchronised cursor movement with two TEdits

Synchronised cursor movement with two TEdits

I have a form with two TEdit components, both containing identical text
strings.  If I move the cursor to a given position in Edit1 how do I get the
cursor to move to exactly the same position in Edit2 (and vice versa).  It
would also be nice if the scroll bars were synchronised but I haven't been
able to work that out either- all suggestions gratefully received!

Thanks in advance

Alun Griffiths

 

Re:Synchronised cursor movement with two TEdits


Oops, sorry, the two components were TMemos not TEdits
Quote
griffinpc wrote in message <39919081_1@dnews>...
>I have a form with two TEdit components, both containing identical text
>strings.

Re:Synchronised cursor movement with two TEdits


There are windows API calls to get and set the selected area of a windows
control which can be used to synchronize the selected area of multiple
controls. Note that both TEdit* and TMemo* are descendants of the
TWinControl* class. The following function can be passed any descendant of
the TWinControl* class and results in the behaviour you described (in order
to see the selected area of a non-focused control make sure that you set the
"HideSelection" property of the control to false):

void SynchSelection(TWinControl* Source, TWinControl* Dest)
{
     unsigned long retVal = ::SendMessage(Source->Handle, EM_GETSEL, 0, 0L);
     WPARAM startPos = LOWORD(retVal);
     LPARAM endPos = HIWORD(retVal);
    ::SendMessage(Dest->Handle, EM_SETSEL, startPos, endPos);

Quote
}

//The above function does not synchronize the scroll bars however. If you
want a TMemo* specific function that will synchronize both the selected area
of the 2 memo boxes and the scroll bars, then just do this:

void SynchSelection(TMemo* Source, TMemo* Dest)
{
        Dest->SelStart = Source->SelStart;
        Dest->SelLength = Source->SelLength;

Quote
}

good luck,

Patrick Cosmo

Quote
"griffinpc" <griffi...@dial.pipex.com> wrote in message

news:39919081_1@dnews...
Quote
> I have a form with two TEdit components, both containing identical text
> strings.  If I move the cursor to a given position in Edit1 how do I get
the
> cursor to move to exactly the same position in Edit2 (and vice versa).  It
> would also be nice if the scroll bars were synchronised but I haven't been
> able to work that out either- all suggestions gratefully received!

> Thanks in advance

> Alun Griffiths

Other Threads