Solved

Dashed Line at TRichEdit

Posted on 1998-04-12
1
230 Views
Last Modified: 2010-04-06
I want to make dash line TRichEdit, like in WordPad when you setup indent. So, the dashline just appear while left mousebutton pressed, and after left mousebutton is released, then the dashed line is also disappeared.

Thanks...

Daniel
0
Comment
Question by:daniel_c
1 Comment
 
LVL 2

Accepted Solution

by:
Hagen040798 earned 50 total points
ID: 1361422
unit DrawLine;

interface

{This Example paint a dotted Line in the Client from Editor}

type
  TTextEditWin = class(TForm)
    Editor: TRichEdit;
    LeftRulerItem: TLabel;
    RightRulerItem: TLabel;
  private
    FDragging: Boolean; {is RulerItem dragged ?}
    FLine: Boolean; {is DragLine painted ?}
  end;

implementation

procedure Updatepaint;

function UP(Wnd: hWnd; lParam: LParam): Bool; stdcall; export;
begin
  Result := True;
  UpdateWindow(Wnd);
  EnumChildWindows(Wnd, @Up, lParam);
end;

procedure UpdatePaint; {paint all needed Windows}
begin
  EnumWindows(@UP, 0);
end;

{Method's handled by Left-/RightRulerItem}
procedure TTextEditWin.RulerItemMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  SetFocus;
  UpdatePaint;
  FDragging := True;
  SetCaptureControl(TControl(Sender));
end;

procedure TTextEditWin.RulerItemMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  SetCaptureControl(nil);
  FDragging := False;
  SetRulerPos(TControl(Sender), TControl(Sender).Left, not (ssCtrl in Shift));
end;

procedure TTextEditWin.RulerItemMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  if FDragging then
    SetRulerPos(TControl(Sender), TControl(Sender).Left + X, not (ssCtrl in Shift));
end;

procedure TTextEditWin.SetRulerPos(Ruler: TControl; Pos: Integer; const Rastered: Boolean);

  procedure DrawLine;
  begin
    with TControlCanvas.Create do
    try
      Control := Editor;   {Richedit-Control}
      Pen.Color := clBlack;
      Pen.Style := psDot;
      Pen.Mode := pmXor;
      MoveTo(Ruler.Left + 4, 0); {Ruler.Width div 2 = 4}
      LineTo(Ruler.Left + 4, Editor.ClientHeight);
    finally
      Free;
    end;
  end;

begin
  if Ruler.Visible and ((Ruler.Left <> Pos) or (FDragging and not FLine)) then
  begin
    if FDragging and FLine then DrawLine;
    Ruler.Left := Pos;
    if FDragging then
    begin
      DrawLine;
      FLine := True;
    end;
  end else
    if (not FDragging or not Ruler.Visible) and FLine then
    begin
      DrawLine;
      FLine := False;
      Ruler.Left := Pos;
    end;
end;

end.

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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