Solved

Floating image over panels

Posted on 2013-11-24
16
470 Views
Last Modified: 2013-11-29
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
Comment
Question by:hidrau
  • 8
  • 4
  • 4
16 Comments
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 25

Accepted Solution

by:
Sinisa Vuk earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
maybe this custom component will work:
http://www.rsdn.ru/forum/delphi/1642145.1
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 1

Author Closing Comment

by:hidrau
Comment Utility
When you can, please, answer my last question. Thanks
0
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
Be sure I'll help if I'll can do it :)
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
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
 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
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
 
LVL 1

Author Comment

by:hidrau
Comment Utility
Thanks Sinisav.

I understood now :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now