Solved

Create a margin in a rich edit control?

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 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