Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to move EditBox in a RichEdit Control

dubidubi Member Posts: 121
Hi guys,
I want to move a Editbox to a coordinate in RichEdit control.
That is getting the CaretPosition(the Blinking cursor) in RichEdit control,the Editbox has to be moved to the current CaretPosition in the RichEdit control.
I really don't know how to use ClientToScreen and ScreenToClient functions.

Thanks for your replies.

Dubi

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi guys,
    : I want to move a Editbox to a coordinate in RichEdit control.
    : That is getting the CaretPosition(the Blinking cursor) in RichEdit control,the Editbox has to be moved to the current CaretPosition in the RichEdit control.
    : I really don't know how to use ClientToScreen and ScreenToClient functions.
    :
    : Thanks for your replies.
    :
    : Dubi
    :
    :
    First off, the ClientToScreen() and ScreenToClient() are not functions, but methods of the TControl object. This is important, because it defines the client.
    The way to go is to convert the CaretPosition into a screen position, then convert the screen position to a position on the RichEdit's parent. This gives you the position at which the edit needs to be.
  • dubidubi Member Posts: 121
    : : Hi guys,
    : : I want to move a Editbox to a coordinate in RichEdit control.
    : : That is getting the CaretPosition(the Blinking cursor) in RichEdit control,the Editbox has to be moved to the current CaretPosition in the RichEdit control.
    : : I really don't know how to use ClientToScreen and ScreenToClient functions.
    : :
    : : Thanks for your replies.
    : :
    : : Dubi
    : :
    : :
    : First off, the ClientToScreen() and ScreenToClient() are not functions, but methods of the TControl object. This is important, because it defines the client.
    : The way to go is to convert the CaretPosition into a screen position, then convert the screen position to a position on the RichEdit's parent. This gives you the position at which the edit needs to be.
    :

    Thanks Zibadian for your reply.
    But I cannot fullfill my need with your suggestion.
    As you said,first I have converted the CaretPosition of RichEdit to Screen Coordiantes using GetCaretPos(),and then convert to RichEdit's parent.The code is

    int caretpos_x,caretpos_y;
    TPoint pPoint;
    GetCaretPos(&pPoint);
    pPoint=RichEdit1->ClientToScreen(
    RichEdit1->ClientToParent(pPoint,this));

    caretpos_x=pPoint.x;
    caretpos_y=pPoint.y;
    EditBox1->Left=caretpos_x;
    EditBox1->Top=caretpos_y;
    Also the coordinates varies when the form is Maximised or minimized.

    By the way I am using C++ builder,but it is easy to convert Delphi code to C++ builder code.So you can give it in Delphi code,no problem.

    Thanks Zibadian.
    Dubi


  • zibadianzibadian Member Posts: 6,349
    : : : Hi guys,
    : : : I want to move a Editbox to a coordinate in RichEdit control.
    : : : That is getting the CaretPosition(the Blinking cursor) in RichEdit control,the Editbox has to be moved to the current CaretPosition in the RichEdit control.
    : : : I really don't know how to use ClientToScreen and ScreenToClient functions.
    : : :
    : : : Thanks for your replies.
    : : :
    : : : Dubi
    : : :
    : : :
    : : First off, the ClientToScreen() and ScreenToClient() are not functions, but methods of the TControl object. This is important, because it defines the client.
    : : The way to go is to convert the CaretPosition into a screen position, then convert the screen position to a position on the RichEdit's parent. This gives you the position at which the edit needs to be.
    : :
    :
    : Thanks Zibadian for your reply.
    : But I cannot fullfill my need with your suggestion.
    : As you said,first I have converted the CaretPosition of RichEdit to Screen Coordiantes using GetCaretPos(),and then convert to RichEdit's parent.The code is
    :
    : int caretpos_x,caretpos_y;
    : TPoint pPoint;
    : GetCaretPos(&pPoint);
    : pPoint=RichEdit1->ClientToScreen(
    : RichEdit1->ClientToParent(pPoint,this));
    :
    : caretpos_x=pPoint.x;
    : caretpos_y=pPoint.y;
    : EditBox1->Left=caretpos_x;
    : EditBox1->Top=caretpos_y;
    : Also the coordinates varies when the form is Maximised or minimized.
    :
    : By the way I am using C++ builder,but it is easy to convert Delphi code to C++ builder code.So you can give it in Delphi code,no problem.
    :
    : Thanks Zibadian.
    : Dubi
    :
    :
    :
    The code I had in mind is this:
    [code]
    var
    P: TPoint;
    begin
    P := RichEdit1.CaretPos; // Get coordinates of the cursor
    P := RichEdit1.ClientToScreen(P); // Convert to screen
    P := RichEdit1.Parent.ScreenToClient(P); // Convert to parent
    EditBox1.Left := P.X; // Place editbox
    EditBox1.Top := P.Y;
    end;
    [/code]
    This code is untested, and might not work correctly.
  • dubidubi Member Posts: 121
    : : : : Hi guys,
    : : : : I want to move a Editbox to a coordinate in RichEdit control.
    : : : : That is getting the CaretPosition(the Blinking cursor) in RichEdit control,the Editbox has to be moved to the current CaretPosition in the RichEdit control.
    : : : : I really don't know how to use ClientToScreen and ScreenToClient functions.
    : : : :
    : : : : Thanks for your replies.
    : : : :
    : : : : Dubi
    : : : :
    : : : :
    : : : First off, the ClientToScreen() and ScreenToClient() are not functions, but methods of the TControl object. This is important, because it defines the client.
    : : : The way to go is to convert the CaretPosition into a screen position, then convert the screen position to a position on the RichEdit's parent. This gives you the position at which the edit needs to be.
    : : :
    : :
    : : Thanks Zibadian for your reply.
    : : But I cannot fullfill my need with your suggestion.
    : : As you said,first I have converted the CaretPosition of RichEdit to Screen Coordiantes using GetCaretPos(),and then convert to RichEdit's parent.The code is
    : :
    : : int caretpos_x,caretpos_y;
    : : TPoint pPoint;
    : : GetCaretPos(&pPoint);
    : : pPoint=RichEdit1->ClientToScreen(
    : : RichEdit1->ClientToParent(pPoint,this));
    : :
    : : caretpos_x=pPoint.x;
    : : caretpos_y=pPoint.y;
    : : EditBox1->Left=caretpos_x;
    : : EditBox1->Top=caretpos_y;
    : : Also the coordinates varies when the form is Maximised or minimized.
    : :
    : : By the way I am using C++ builder,but it is easy to convert Delphi code to C++ builder code.So you can give it in Delphi code,no problem.
    : :
    : : Thanks Zibadian.
    : : Dubi
    : :
    : :
    : :
    : The code I had in mind is this:
    : [code]
    : var
    : P: TPoint;
    : begin
    : P := RichEdit1.CaretPos; // Get coordinates of the cursor
    : P := RichEdit1.ClientToScreen(P); // Convert to screen
    : P := RichEdit1.Parent.ScreenToClient(P); // Convert to parent
    : EditBox1.Left := P.X; // Place editbox
    : EditBox1.Top := P.Y;
    : end;
    : [/code]
    : This code is untested, and might not work correctly.
    :


    Thanks Zibadian.
    Your code works with one line modification.
    I used GetCaretPos(&pPoint) instead of RichEdit1->CaretPos;
    But that too works correctly only when the form is maximised at the first time when executed.
    i.e,the form must be maximized when it runs.Then the form can be
    resized.
    I don't know why?

    TPoint pPoint;

    GetCaretPos(&pPoint);
    pPoint=RichEdit1->ClientToScreen(pPoint);
    pPoint=RichEdit1->Parent->ScreenToClient(pPoint);

    caretpos_x=pPoint.x;
    caretpos_y=pPoint.y;
    EditBox1->Left=caretpos_x;
    EditBox1->Top=caretpos_y;

    Dubi


Sign In or Register to comment.