Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1049
  • Last Modified:

Painting on TScrollBox

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
Stern
Asked:
Stern
  • 4
  • 3
1 Solution
 
jm verdiCommented:
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
 
SternAuthor Commented:
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
 
viktornetCommented:
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
Independent Software Vendors: 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!

 
viktornetCommented:
Oooopppssss....
I've got a mistake over there......
Image.Canvas.Draw(0,0,MyBitmap);
Sorry.....
Viktor Ivanov
0
 
SternAuthor Commented:
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
 
SternAuthor Commented:
I've really forgotten how should I accept the answer.
0
 
viktornetCommented:
I'll make it an answer and then you can accept it if you want to..ok?

Viktor Ivanov
0
 
viktornetCommented:
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

Independent Software Vendors: 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!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now