BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Positioning TShape in TScrollbox After Drop

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using
View previous topic :: View next topic  
Author Message
Elliott Shevin
Guest





PostPosted: Mon Nov 24, 2003 2:28 am    Post subject: Positioning TShape in TScrollbox After Drop Reply with quote



I've got a TShape inside a TScrollbox. The TShape sits on top of a TImage,
also inside and filling the TScrollbox, and can be dragged and dropped on
the TImage. I reposition the TShape when it's dropped.

My problem is that when the TScrollbox has been scrolled, the TShape is
positioned further to the right than my setting (if the box has been
scrolled right), or lower then my setting (if the box has been scrolled
down). And I can't figure out how to compensate.

Here's the handler.

procedure TForm1.Image1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
with Shape1 do begin
Left := X;
Top := Y;
Invalidate;
end;
end;

Can anyone help?

Thanks,
Elliott


Back to top
Kurt Barthelmess
Guest





PostPosted: Mon Nov 24, 2003 11:36 am    Post subject: Re: Positioning TShape in TScrollbox After Drop Reply with quote



"Elliott Shevin" <shevine (AT) no-aol (DOT) com-spam> wrote:

Quote:
I've got a TShape inside a TScrollbox. The TShape sits on top of a TImage,
also inside and filling the TScrollbox, and can be dragged and dropped on
the TImage. I reposition the TShape when it's dropped.

My problem is that when the TScrollbox has been scrolled, the TShape is
positioned further to the right than my setting (if the box has been
scrolled right), or lower then my setting (if the box has been scrolled
down). And I can't figure out how to compensate.

I'm not sure I understand. If the TShape is a child of the TScrollBox,
it should be scrolled along with the rest of the content of the
TScrollBox. If you don't want the shape to move when you scroll, don't
make it a child of the TScrollbox, make it a child of the form.

Quote:
procedure TForm1.Image1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
with Shape1 do begin
Left := X;
Top := Y;
Invalidate;
end;
end;

Is the problem initial positioning? If so, adjust the coordinates to
reflect the scrollbars on the TScrollBox,
ScrollBox1.VertScrollBar.Position and
ScrollBox1.HorzScrollBar.Position.

Good luck.

Kurt


Back to top
Elliott Shevin
Guest





PostPosted: Mon Nov 24, 2003 6:52 pm    Post subject: Re: Positioning TShape in TScrollbox After Drop Reply with quote



[email]kbarthelmess (AT) compuserve (DOT) com[/email] (Kurt Barthelmess (TeamB)) wrote:

Quote:
If you don't want the shape to move when you scroll, don't
make it a child of the TScrollbox, make it a child of the form.

No, I do want it to scroll. But I also want it to land where
the drop occurs, not elsewhere.


Anyway, I ended up with:

procedure TForm1.Image1DragDrop(Sender, Source: TObject; X, Y:
Integer);
begin
with Shape1 do begin
Left := X - ScrollBox1.HorzScrollBar.Position;
Top := Y - ScrollBox1.VertScrollBar.Position;
end;
end;

.... on the realization that X and Y are relative to the
TImage, but the position of Shape1 is relative to the
TScrollbox.

I thought I'd tried this before posting, but I guess not.
The "Invalidate" statement is gone, but that wouldn't change
anything, would it?

Cheers,
Elliott

Back to top
Kurt Barthelmess
Guest





PostPosted: Mon Nov 24, 2003 11:41 pm    Post subject: Re: Positioning TShape in TScrollbox After Drop Reply with quote

"Elliott Shevin" <shevine (AT) nospam (DOT) aol.com> wrote:

Quote:
No, I do want it to scroll. But I also want it to land where
the drop occurs, not elsewhere.

Anyway, I ended up with:

procedure TForm1.Image1DragDrop(Sender, Source: TObject; X, Y:
Integer);
begin
with Shape1 do begin
Left := X - ScrollBox1.HorzScrollBar.Position;
Top := Y - ScrollBox1.VertScrollBar.Position;
end;
end;

That's perfect.

Quote:
I thought I'd tried this before posting, but I guess not.
The "Invalidate" statement is gone, but that wouldn't change
anything, would it?

No. Invalidate doesn't move anything; it just forces it to be redrawn.

Good luck.

Kurt


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.