Solved

Problem with Image inside TScrollBox and scrolling

Posted on 2006-10-19
3
911 Views
Last Modified: 2010-04-16
Hi everyone,

I have a TImage inside a TScrollBox. The image is bigger in dimension than the TScrollBox so scrollbars appear on the TScrollBox. I redraw/refresh the TImage everytime it is clicked via onmousedown event. My problem is when the area I click is in the non-visible part of the TImage, which means I have to scroll down or to the right. After redrawing/refreshing the TImage the scrollbars of the scrollbox return to 0 position. I use the following code to scroll back to the non-visible part where the mouse was clicked:

i := GetScrollPos(SBx_DayView.Handle, SB_HORZ);
SetScrollPos(SBx_DayView.Handle, SB_HORZ, i, true);
j := GetScrollPos(SBx_DayView.Handle, SB_VERT);
SetScrollPos(SBx_DayView.Handle, SB_VERT, j, true);

The scrollbox scrolls but view is not scrolled to the (non-visible) part of the image where the mouse was clicked.

I've also tried using:

xpos := SBx_DayView.HorzScrollBar.ScrollPos;
ypos := SBx_DayView.VertScrollBar.ScrollPos;
//refresh image code here
SBx_DayView.ScrollBy(xpos, ypos);

and

xpos := SBx_DayView.HorzScrollBar.ScrollPos;
ypos := SBx_DayView.VertScrollBar.ScrollPos;
//refresh image code here
SBx_DayView.HorzScrollBar.Position := xpos;
 SBx_DayView.VertScrollBar.Position := ypos;

but none of those work.

Can anyone suggest an workaround?

Thanks in advance :)
0
Comment
3 Comments
 
LVL 26

Assisted Solution

by:Russell Libby
Russell Libby earned 100 total points
ID: 17765336

Can you the show the code used for "refreshing" the TImage? If the width / height of the image does not change, it would seem like it would be better to get the code to work so that the scroll pos does not reset.

Russell
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 100 total points
ID: 17770424
I do not get a problem calling .Refresh or .Repaint
Is it possible that you are resizing the TImage/recreating the TImage, and that is why the scrollbars are reverting to 0,0 ?
If you are reloading the image from disk, or doing a "image1.picture.assign(mypic)" you are likely to get this problem.
If you are trying to draw on the timage, try just paiting to the .Picture.Bitmap.Canvas property
0
 

Author Comment

by:dabestprogrammerindauniverse
ID: 17771051
Hi guys,

I have discovered the problem and indeed as you guys have said it has to do with resizing the TImage. I've commented the image resize code and it works perfectly.

Sorry but I have found the solution a few minutes after i've posted my question, but am willing to split the points up for the effort.

Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 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