• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

Create a margin in a rich edit control?

I want to create a working margin at the left of a rich edit control. This makes the text easier to read. At present I have a panel (white with no borders) beside the rich edit and this gives the desired look.

| Panel| Rich edit                   |
|      |                             |
|      |                             |

The problem is when users try to select text from the beginning of a line in the rich edit but start their selection on the panel. This means the selection operation does not work as they continue to drag the mouse from the panel over the rich edit.

Can someone tell me how to write code for mouse events on the panel that will let the selection action work in the rich edit even though it starts from the panel.
Or can someone show me how to alter the width of the very narrow margin that is at the left of rich edit controls.

With thanks - Dan
0
seabear
Asked:
seabear
  • 2
1 Solution
 
kretzschmarCommented:
here is sample
it applys to the current paragraph,
just set it before inserting text

unit re_left_margin_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls,
  richedit;  //richedit is used

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    RichEdit1: TRichEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  ParaFormat : TParaFormat;
begin
  ParaFormat.cbSize := SizeOf(ParaFormat);
  ParaFormat.dxStartIndent := strtoint(edit1.text);

  ParaFormat.dwMask := PFM_STARTINDENT;
  richedit1.perform(EM_SETPARAFORMAT,0,Integer(@ParaFormat));
end;

end.


hope this helps

meikl ;-)
0
 
kretzschmarCommented:
appendix:
use high values (50, 100, 200 or more)
as you need
0
 
Slick812Commented:
hello seabear, I tried using a method similar to kretzschmar's except usint the RichEdit Paragraph -
RichEdit1.Paragraph.LeftIndent := 16;
a while back to get a type of margin on a TRichedit, I tried looping through the Lines Count and setting the LeftIndent in the RichEdit.OnChange, but I had no Luck? ? But with your method of using a TPanel you could try using the panel's OnMouseDown


procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
RichEdit1.SetFocus;
{first get the focus to the RichEdit}
SetCapture(RichEdit1.Handle);
{get the mouse messages to go to RichEdit}
SendMessage(RichEdit1.Handle, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(0,Y));
{fire a mouse click on the RichEdit}
end;

- - - - -  - -- - -  - - - -
this seemed to work for me


0
 
seabearAuthor Commented:
Hi Slick812 and Meikle,
  Thank you both for your answers. Sending a mouse down message to the panel fits simply into my existing design and is independant of what is being done to the text so that is the approach I will use. I am very pleased by how nicely it works.

Thanks again - Dan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now