Solved

Dashed Line at TRichEdit

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now