Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Drawing on Rich Edit's Canvas

Posted on 1999-07-07
12
Medium Priority
?
1,507 Views
Last Modified: 2010-07-27
How can I draw a Rectangle on a Rich Edit's Canvas?
This is the code I use for it:

procedure TMyRichEdit.WMPaint(var Msg: TWMPaint);
var
  Canvas : TCanvas;
begin
  inherited;
  Canvas := TCanvas.Create;
  with Canvas do
  try
    Msg.Result := 0;
    Handle := Msg.DC;
    Canvas.Brush.Color := clBlue;
    FrameRect(Rect(10, 10, 200, 100)); { here I get error:  EEInvalidOperation "Canvas does not allow drawing" }
  finally
    Canvas.Free;
  end;
end;
 
I use Delphi 4 and RichEdit98
0
Comment
Question by:kotik
[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
  • 6
  • 5
12 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387132
That doesn't work because a canvas is an abstract drawing space.
0
 
LVL 2

Author Comment

by:kotik
ID: 1387133
When I do it this way, everithing is OK:

function TMyRichEdit.Test: integer;
var
  DC : HDC;
  Brush : TBrush;
begin
  try
    Brush := TBrush.Create;
    Brush.Color := clRed;
    DC := GetDC(Handle);
    FrameRect(DC, Rect(10, 10, 200, 100), Brush.Handle);
  finally
  end;
end;

Epsylon: How can I use a Canvas for a Rich Edit?
Thanks
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387134
Ok, I don't know if that works. I suggest you give it a try:


In the constructor TMyRichEdit.Create do

  FCanvas := TControlCanvas.Create; // declare FCanvas in your class
  TControlCanvas(FCanvas).Control := Self;


In destructor TMyRichEdit.Destroy do

  FCanvas.Free;



Use FCanvas to draw to.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Expert Comment

by:Epsylon
ID: 1387135
By the way, there is no need to create a TBrush object....
0
 
LVL 2

Author Comment

by:kotik
ID: 1387136
Thank you Epsylon.
I'll try it...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1387137
NO! NO! NO!

The code is correct... One of your calls is not correct... try this code..

procedure TMyRichEdit.WMPaint(var Msg: TWMPaint);
             var
               Canvas : TCanvas;
             begin
               inherited;
               Canvas := TCanvas.Create;
               with Canvas do
               try
                 Msg.Result := 0;
                 Handle := Msg.DC;
                 Canvas.Brush.Color := clBlue;
                 Canvas.Rectangle(Rect(10, 10, 200, 100));
               finally
                 Canvas.Free;
                 Canvas.Handle := 0;
               end;

try it....

..-=ViKtOr=-..
             end;
0
 
LVL 2

Author Comment

by:kotik
ID: 1387138
Hi ViKtOr.
Sorry, but your code does the same thing as mine and also gives the same error message.

By the way, the Rectangle procedure's params are integers and not a TRect.

I solved the problem by myself, so I'll delete this question.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387139
Was was the result of my suggestion? And can you give us a hint of how you solved it? I would be pleased to hear  :o)
0
 
LVL 2

Author Comment

by:kotik
ID: 1387140
It's a very simple solution:
I decided not to use a TCanvas object ;-)

This is my code:

procedure TMyRichEdit.DrawTable;
var
  DC : HDC;
  OldColor : TColor;
  R : TRect;
begin
  R := TblEditor.GetTableRect;
  if (R.Right <> 0) and (R.Bottom <> 0) then begin
    OldColor := Brush.Color;
    Brush.Color := clBlue;
    DC := GetDC(Handle);
    FrameRect(DC, R, Brush.Handle);
    Brush.Color := OldColor;
  end
end;

0
 
LVL 2

Author Comment

by:kotik
ID: 1387141
Anyway, Epsylon, you helped me with your suggestion.
And I am not greedy and you can get the points if you submit any answer :)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387142
Hi Kotik, you can get your points back if you post a request for deletion of this question.
You can do that in the Customers Service area.

But if you think that I deserve the points, please say so, then I'll answer it.

Epsylon.
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 400 total points
ID: 1387143
Well, what'da heck  :o)

since my suggestion helped you, I answer it anyway.

You can always reject this if you may change your mind.

I just hope that you're making progress....

Thanks a lot.

Eps.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

670 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