Solved

Dashed Line at TRichEdit

Posted on 1998-04-12
1
240 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

Technology Partners: 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!

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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