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

Create compoennt with TPanel and TImage


Hello,
I want to create a component.  A TImage on a TPanel.  The user should be abled to select the image.  How can I do that ??
0
frdep
Asked:
frdep
1 Solution
 
esoftbgCommented:
It is easy to create a component:  TImage on a TPanel, but it it is not easy (for me) to able to select the Image ....
I remember there is an old question that was answered by Ferruccio68 about the selection ....
Do you need an example about: TImage on a TPanel, but without ability for selection ?
0
 
mikelittlewoodCommented:
Does the OnClick event of a TImage not work very well esoftbg?
0
 
esoftbgCommented:
Hi mikelittlewood, I just tested my component:

procedure TForm1.Panel_with_Image1ImageClick(Sender: TObject);
begin
  ShowMessage('Test Image OnClick');
end;

It works (It raises above message) on every clicking on it ....
0
Industry Leaders: 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!

 
mikelittlewoodCommented:
ok ..
I just wondered why you wrote
>It is easy to create a component:  TImage on a TPanel, but it it is not easy (for me) to able to select the Image <
0
 
esoftbgCommented:
I really never have been programmed any Image selection, so it is not easy for me. I mean may be partial selection and / or full Image selection ....
0
 
ZhaawZSoftware DeveloperCommented:
frdep, what do you mean with "the user should be abled to select the image"?
0
 
frdepAuthor Commented:

The programmer who use the component should be abled to assign a picture, not the final user.
So, I drop the component on the form.  On the component, I have a property "Picture" I can select ( like a normal TImage ) or assigne the image by programmation ( TPanelImage1.Picture := ... )
0
 
esoftbgCommented:
you will be abled to assign a picture both at design time and at runtime .... No problem about that .... It is like a normal TImage. It is possible to be used under Delphi 6, Delphi 7 and Later versions ....
0
 
esoftbgCommented:
download the component and an example application from:
page:        http://www.geocities.com/esoftbg/
  link:        Q_21336613.zip        Create compoennt with TPanel and TImage
0
 
esoftbgCommented:
This is not a new answer:

unit Panel_with_Image;

interface

uses
  SysUtils, Classes, Controls, StdCtrls, ExtCtrls;

type
  TPanel_with_Image  =  class(TPanel)
    private     { Private declarations }
      FImage:     TImage;
      procedure   SetImage(const Value: TImage);
    protected   { Protected declarations }
    public      { Public declarations }
      constructor Create(AOwner: TComponent); override;
      procedure   Paint; override;
      destructor  Destroy; override;
    published   { Published declarations }
      property    Image: TImage read FImage write SetImage;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('ESoft', [TPanel_with_Image]);
end;

constructor TPanel_with_Image.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Caption := ' ';
  FImage := TImage.Create(Self);
  FImage.SetSubComponent(True);
  FImage.Parent := Self as TWinControl;
  FImage.Name := 'Image';

  RePaint;
end;

procedure TPanel_with_Image.Paint;
begin
  inherited;
  if Assigned(FImage) then
  begin
    FImage.Height := Self.Height;
    FImage.Width := Self.Width;
    FImage.Left := 0;
    FImage.Top := 0;
  end;
end;

procedure TPanel_with_Image.SetImage(const Value: TImage);
begin
  FImage.Assign(Value);
  Invalidate;
end;

destructor  TPanel_with_Image.Destroy;
begin
  if Assigned(Image) then
    Image.Destroy;
  inherited Destroy;
end;

end.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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