Solved

Painting on TScrollBox

Posted on 1998-07-12
8
918 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

21 Experts available now in Live!

Get 1:1 Help Now