Solved

Create a margin in a rich edit control?

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 62
Delphi cmd execution 6 60
Mobile Keyboard covers the display of the TMemo 3 86
Intraweb download file link ? 1 132
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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