[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Dashed Line at TRichEdit

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
daniel_c
Asked:
daniel_c
1 Solution
 
Hagen040798Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now