Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 840019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:33:28+00:00 2026-05-15T05:33:28+00:00

Using the following code in Delphi 2007: procedure TfrmTest.PaintBox1Paint(Sender: TObject); const Rect_Size = 10;

  • 0

Using the following code in Delphi 2007:


procedure TfrmTest.PaintBox1Paint(Sender: TObject);
const
  Rect_Size = 10;
begin
  PaintBox1.Canvas.Brush.Color := clYellow;
  PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.width, PaintBox1.height));

  PaintBox1.Canvas.Brush.Color := clRed;
  DrawARect(PaintBox1.Canvas, 0, 0, Rect_Size, Rect_Size);
end;

procedure TfrmTest.DrawARect(ACanvas: TCanvas; iLeft, iTop, iWidth, iHeight: Integer);
var
  rgnMain: HRGN;
begin
  rgnMain := CreateRectRgn(iLeft, iTop, iLeft + iWidth, iTop + iHeight);
  try
    SelectClipRgn(ACanvas.handle, rgnMain);
    ACanvas.FillRect(ACanvas.ClipRect);
    SelectClipRgn(ACanvas.handle, 0);
  finally
    DeleteObject(rgnMain);
  end;
end;

I get this:
(Yellow area shows boundaries of PaintBox1).

alt text http://www.freeimagehosting.net/uploads/62cf687d29.jpg

(Image shows a form with a yellow box [PaintBox1] in the center. However my red rectange [rgnMain] has been drawn at pos 0,0 on the form)

My expectation was that the red rectangle would be at the top left of the PaintBox1 canvas, not the form’s canvas. Why is it not? Can regions only be used with controls that have a Windows handle?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:33:29+00:00Added an answer on May 15, 2026 at 5:33 am

    Device Contexts require a window handle. What VCL does for non-windowed controls is to offset the view port of the DC acquired for the TWinControl they are on, by using SetWindowOrgEx in TWinControl.PaintControls. The new view port is in logical units. So for ‘TGraphicControl’s, which does not descend from TWinControl, you can use GDI functions which work on logical coordinates. See the remarks section for SelectClipRgn, which says the coordinates should be specified in device units. You’d offset the region or the coordinates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Delphi 2007 I can write the following code: interface TTestType = (ttTest1, ttTest2);
How will the Delphi compiler compiles the following code ; uses a_big_unit; procedure TForm1.Button1Click(Sender:
I'm trying to get the Global Interface Table by using the following code (Delphi):
Please forgive the verbosity of the following code example. Using Delphi 2009, I created
I have managed to use SAPI Text-To-Speech in Delphi/Lazarus by using the following code:
I'm using Delphi 2009 and get some strange errors using the following code segment:
Using RDO 4.8.0.1184 with Delphi 2006 on Exchange 2007 SP3 I have the following
Using following code I try to get updated list of checkbuttons' corresponding text values,
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
I am creating date using following code try { newdatetime = new DateTime(2012, 2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.