• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

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
0
hidrau
Asked:
hidrau
  • 8
  • 4
  • 4
1 Solution
 
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
 
Sinisa VukCommented:
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now