Solved

Painting on TScrollBox

Posted on 1998-07-12
8
949 Views
Last Modified: 2010-04-04
How can I draw something on TScrollBox (it has no Canvas property). I tried to put TImage on it, but I need something like a background, and when I make TImage's Align alClient and draw on its canvas, and then I have to scroll it, only that part which was visible from the beginning remains painted, and it doesn#t paint to the rest of Canvas. Waht can I do here?

And one more problem: how can I refresh the TImage's canvas? (when I have to change the image, it is painted over the old one, and the problem is that I have to draw on the canvas (I can't use LoadFromFile and so on)).
0
Comment
Question by:Stern
  • 4
  • 3
8 Comments
 

Expert Comment

by:jm verdi
ID: 1357745
Hi stern,

I would say: you don't need scrollbox to scroll a bitmap.
Just put a TImage and 2 scrollbar on your form.
Load bitmap and display it on the canvas of the Timage, then
modify the maxvalue of these scrollbars to match the size of the bitmap, then attach a function for scrollbars OnChange like:
Bitmap.Canvas.Draw(Hscroll.Position,VScroll.Position,Bitmap)

The bitmap will scroll smothly when you click on your scrollbars.

But if you need scrollbox for another usage, than i have no suggestion :-(

Jean marie
0
 

Author Comment

by:Stern
ID: 1357746
Well, sorry, it's not what I need. Let it be not a scroll box, but a simple panel, or it doesn't mean. The problem is that it doesn't paint on the rest of the canvas, when the TImage becomes larger than it was first. So when I resize a form to the larger size (or scroll, it's not a problem), only the first visible part becomes painted.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1357747
Hello Stern,
First you need to remove the content of the TImage comp and then draw on it. It can be done like this:

Image1.Canvas.Brush.Color := ClBtnFace;//Set the color
//the color has to be same as your form's color or it's parent}
Image1.Canvas.FillRect(Canvas.ClipRect);//Clean up the canvas of the Image
//then draw whatever you want
Image.Draw(0,0,MyBitmap);

Viktor Ivanov
0
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!

 
LVL 10

Expert Comment

by:viktornet
ID: 1357748
Oooopppssss....
I've got a mistake over there......
Image.Canvas.Draw(0,0,MyBitmap);
Sorry.....
Viktor Ivanov
0
 

Author Comment

by:Stern
ID: 1357749
Thank you very much! I see, I could do it myself, but you know, there are always these small simple things which make us crazy.
0
 

Author Comment

by:Stern
ID: 1357750
I've really forgotten how should I accept the answer.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1357751
I'll make it an answer and then you can accept it if you want to..ok?

Viktor Ivanov
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1357752
Hello Stern,
  Here is the answer...  
   First you need to remove the content of the TImage comp and then draw on
     it. It can be done like this:

     Image1.Canvas.Brush.Color := ClBtnFace;//Set the color
     //the color has to be same as your form's color or it's parent}
     Image1.Canvas.FillRect(Canvas.ClipRect);//Clean up the canvas of the
     Image
     //then draw whatever you want
     Image1.Canvas.Draw(0,0,MyBitmap);

     Viktor Ivanov
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Mdi application Child forms get behind control 7 307
Delphi selector screen 2 92
How to make Sign in, using Clientdataset? 1 33
Delphi, TImage, Png 2 20
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

763 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