Solved

Dashed Line at TRichEdit

Posted on 1998-04-12
1
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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