what is the order to paint/refresh components on my form ...

Posted on 2008-11-18
Last Modified: 2012-05-05
I have a form to display a bitmap with scrollbars on each side and a panel (color blue) on which a put a Paintbox.

a) If I move the scrollbars the Bitmap is displayed in the paintbox correctly

b) If a add the command  MyPaintBox.refresh in the .DisplayBitmap function,
   I see only the blue panel behind the paintbox

c) If I call the ScrollbarMove function eg. after the resize function I also see only the
   blue panel and not my bitmap

Any Input is highly welcome


 *   If you move the scrollbar, go and update the Paintbox


procedure TViewBitMapForm.ScrollbarMove(Sender : TObject);


    DisplayBitmap(xScrollBar.Position, yScrollBar.Position);



 *  Function:  Copy the Bitmap to the PaintBox

 *  Input :  xpixel :  x postition of the scrollbar

 *           ypixel :  y position of the scrollbar


 * OutPut:  -----  (show the Bitmap)


procedure TViewBitMapForm.DisplayBitmap(xpixel, ypixel : Integer);



   BOOL BitBlt(

      HDC hdcDest, // handle to destination DC

      int nXDest,  // x-coord of destination upper-left corner

      int nYDest,  // y-coord of destination upper-left corner

      int nWidth,  // width of destination rectangle

      int nHeight, // height of destination rectangle

      HDC hdcSrc,  // handle to source DC

      int nXSrc,   // x-coordinate of source upper-left corner

      int nYSrc,   // y-coordinate of source upper-left corner

      DWORD dwRop  // raster operation code



   if FBitMap <> nil then

             if  not BitBlt(MyPaintBox.Canvas.Handle,0,0,




                     Xpixel  ,

                     Ypixel  , SRCCOPY) then

                     ViewBitMapForm.Caption  := 'Error BitBlt!!';

   // MyPaintBox.refresh;


Open in new window

Question by:BdLm
    LVL 17

    Accepted Solution

    You should draw bitmap in PaintBox OnPaint event.
    Why don't You use ScrollBox?
    LVL 8

    Author Comment

    add this code

    procedure TViewBitMapForm.MyPaintBoxPaint(Sender: TObject);
         DisplayBitmap(xScrollBar.Position, yScrollBar.Position);

    solved my trouble, your answer is fine  :-)
     but I don't understand the sequence of painting components ....
    Any hint ?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now