Solved

Painting on TScrollBox

Posted on 1998-07-12
8
972 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

623 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