Solved

Problem with Image inside TScrollBox and scrolling

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 143
Process Javascript errors with Delphi TWebBrowser 1 135
URL for downloading Google Chrome for Win XP 2 155
CheckListBox usage 3 59
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

773 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