Solved

Create a margin in a rich edit control?

Posted on 2002-07-23
4
402 Views
Last Modified: 2010-04-04
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
Comment
Question by:seabear
  • 2
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7172713
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7172720
appendix:
use high values (50, 100, 200 or more)
as you need
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 200 total points
ID: 7173092
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
 

Author Comment

by:seabear
ID: 7175821
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now