Solved

Problem with Image inside TScrollBox and scrolling

Posted on 2006-10-19
3
914 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
[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
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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