Solved

Create a margin in a rich edit control?

Posted on 2002-07-23
4
405 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

18 Experts available now in Live!

Get 1:1 Help Now