Solved

Problem with Image inside TScrollBox and scrolling

Posted on 2006-10-19
3
897 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

13 Experts available now in Live!

Get 1:1 Help Now