Floating image over panels

Hello guys,

I am trying to find a way to make my image float from one panel to another when I click on the button. But I am having a problem, as you can see in my code, I have a second panel and when the image moves from one panel to another, it goes behind the panels and after finished the moving, the image disappears.

I trying to find a solution in web but I haven't found anything so far, maybe you can help me with this task.

I made the code in Delphi XE4

Thanks
Alex
FloatImage.zip
LVL 1
hidrauAsked:
Who is Participating?
 
Sinisa VukConnect With a Mentor Commented:
Timage is inherited from TGraphicControl which is not have window handle and we cannot set real window z-order. But Panel can be set :-)

Try this - put Timage on TPanel same size as Image and run you code this way:
procedure TForm1.Button1Click(Sender: TObject);
var
 i : Integer;
begin
  for I := 0 to 20 do
  Begin
    Panel4.Top := Panel4.Top + 20;
    Sleep(100);
    Application.ProcessMessages
  End;
end;

Open in new window



I see you old question too. When you do drag and drop of image - you can hide and destroy parent Panel and recreate another on destination or just start dragging Panel too.
0
 
Marco GasiFreelancerCommented:
See if do you like this :

procedure TForm1.Button1Click(Sender: TObject);
var
 i : Integer;
begin
  for I := 0 to 10 do
  Begin
      Image7.Top := Image7.Top + 20;
      Sleep(100);
      Application.ProcessMessages;
  End;
  Image7.Top := -117;
  Image7.Parent := nil;
  Image7.Parent := Panel2;
  for I := 0 to 10 do
  Begin
      Image7.Top := Image7.Top + 20;
      Sleep(100);
      Application.ProcessMessages;
  End;
  Image7.Top := 26;
  Image7.Parent := nil;
  Image7.Parent := Panel3;
end;

Open in new window

0
 
hidrauAuthor Commented:
Hello MarqusG, thanks for your helping and trick.

Hello Sinisav, thanks for your post solution.

I wonder if there isn't any component TImage that  inherited from TGraphicControl. Do you know any? I have the TMS components, I don't know if there is any that has that inheritance. I need to check.

I'll take a look at. I'd like to have only the Timage component without another panel behind it. I need to think what it more suitable to me.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Sinisa VukCommented:
maybe this custom component will work:
http://www.rsdn.ru/forum/delphi/1642145.1
0
 
hidrauAuthor Commented:
Sinisav,

I took a look at it but I wasn't able to install it in my Delphi,
I am at company right now and here we have only Delphi 2010 and
I don't know how to install this component.

I use Delphi XE4 at home, but I am newbie on it, I am used to work with Delphi 7 that I also have in company.

Do you think that it will work for what I want?
0
 
hidrauAuthor Commented:
When you can, please, answer my last question. Thanks
0
 
Marco GasiFreelancerCommented:
Hi hidrau. Just for curiosity: what was wrong with my code? I tested in a project and it moved the panel making it slide down from panel1 to panel3: Did I misunderstood your question?
0
 
hidrauAuthor Commented:
Hi MarqusG,

No, you didn't. I just can't do the way you gave me the code, that is not a good solution for what I was trying to do.

Sinisav gave a solution to workaround and and the notion why the image doesn't go over the panel. Please, don't get me wrong when I close the point giving to him the points.
0
 
Marco GasiFreelancerCommented:
Absolutely no problem for ponts :) sinisav has helped me too many times and he's one of those skilled experts I told you about in your other question.
Good luck with your game development.
Cheers
0
 
hidrauAuthor Commented:
MarqusG, I thank you very much for some helps too. You are also good at delphi. I hope one day to be as good as you and Sinisav.

Well, on the other hand, I hope you can help me ahead.
0
 
Marco GasiFreelancerCommented:
Be sure I'll help if I'll can do it :)
0
 
Sinisa VukCommented:
Found component just like you need (TImageWindow on about.com - great article):
http://delphi.about.com/library/bluc/text/uc092700b.htm
(line where IMAGEWINDOW.DCR is you can remove or create this dcr file and add small bmp image with name TIMAGEWINDOW to show it as image in componets tab)
0
 
hidrauAuthor Commented:
Hello Sinisav,

Once again, thank you and I will test it on weekend.

What I am doing "  a kind of game " it is totally different that is my work. :)
0
 
hidrauAuthor Commented:
Hello Sinisav,

I found a problem when I use TflowPanel, I notice that my Image lost the heigh and left place where it was when its parent was TflowPanel. That doesn't happen with Tpanel.

I tried to work around this, but I didn't have any success.

I wonder if you have any idea how to solve this.

See the example in my file
FloatImage.zip
0
 
Sinisa VukCommented:
You missed one point. When you set parent to some control - control keep left/top position relative to old parent and on new there is a "jump". After you set new parent you must translate relative position to new parent.

old_pt, new_pt, current_pt: TPoint;
new_parent, old_parent: TWincontrol;
...
old_pt := Point(img.Left, img.Top); //current point
old_parent := img.Parent;
new_parent: = Form1;

new_pt := old_pt; //current point
new_pt := old_parent.ClientToScreen(new_pt); //move to screen
new_pt := new_parent.ScreenToClient(new_pt); //back to new parent
img.Parent := new_parent; //move to new parent
img.SetBounds(new_pt.X, new_pt.Y, img.Width, img.Height);

// do move here

//if you want to set new parent back - use same code - but with different parent
old_pt := Point(img.Left, img.Top); //current point
old_parent := img.Parent;
new_parent: = Panel3;

new_pt := old_pt; //current point
new_pt := old_parent.ClientToScreen(new_pt); //move to screen
new_pt := new_parent.ScreenToClient(new_pt); //back to new parent
img.Parent := new_parent; //move to new parent
img.SetBounds(new_pt.X, new_pt.Y, img.Width, img.Height);

Open in new window

0
 
hidrauAuthor Commented:
Thanks Sinisav.

I understood now :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.