PDA

Ver la Versión Completa : Sender en un componente creado


madmai
14-06-2008, 09:00:42
He creado un componente que se componen de un padre (Tpanel) y dentro tiene un speedbutton, el boton ocupa toda la superficie del panel, le he dado un evento al componente que es el click del speedbuton, pues bien quiero que cuando se pulse el speedbuton se active el sender del panel del evento on click del panel pero no se como hacerlo, mi idea es que cuanto utilizo Tpanel(sender) en el codigo de mi programa no me hace caso por que lo que estoy haciendo es click en el speedbutton y no en el panel, no se si me entendeis pero estoy abierto a ideas, gracias de antemano un saludfo

Lepe
14-06-2008, 10:30:05
tienes razón, no te entiendo.

algo de código ayudaría, (sobre todo para saber como tienes definido el evento y cómo lo lanzas).

Saludos

madmai
14-06-2008, 11:04:21
Este es el componente


unit PButon;

interface uses SysUtils, Classes, Controls, ExtCtrls,Buttons, Types, Graphics; type TPButon = class(TPanel)
private FSmallBitmap:TBitmap; FBigOnclick:TNotifyEvent; FBigLabel:String;
FSmallOnclick:TNotifyEvent;
FTag:Integer;

procedure SetSmallBitmap (Value:TBitMap);
procedure settag (Value:Integer);
Procedure SetOnClick (Value: TNotifyEvent);
Procedure SmallSetOnClick (Value: TNotifyEvent);
procedure SetBigLabel (Value:String);
Function GetSmallBitmap:TBitMap;
procedure Resize; override;
{ Private declarations } protected { Protected declarations } public Big,Small:TSpeedbutton; constructor Create(AOWner: TComponent); override;
Destructor Destroy; override;
{ Public declarations } published property BigOnClick:TNotifyEvent read FBigOnclick write SetOnClick;
property SmallOnClick:TNotifyEvent read FSmallOnclick write SmallSetOnClick;
property SmallPicture:TBitmap read GetsmallBitmap write SetSmallBitmap;
property BigCaption:String read FBigLabel write setBigLabel;
property PanelTag:Integer read FTag write settag;
{ Published declarations } end;

procedure Register;

implementation procedure Register;
begin RegisterComponents('Samples', [TPButon]);
end;

procedure TPbuton.settag(Value:Integer);
begin FTag:=Value; end;
procedure TPButon.SetBigLabel (Value:String);
begin FBigLabel:=value; repaint; end;
procedure TPButon.SetSmallBitmap (Value:TBitMap);
begin FSmallBitmap:=Value; small.Glyph:=FSmallBitmap; end;
function TPButon.GetSmallBitmap:Tbitmap;
begin Result:=small.Glyph; end;

Procedure TPButon.SetOnClick (Value: TNotifyEvent);
begin FBigOnClick:=Value; Big.OnClick:=FBigOnClick; end;
Procedure TPButon.SmallSetOnClick (Value: TNotifyEvent);
begin FSmallOnClick:=Value; Small.OnClick:=FSmallOnClick; end;

constructor TPButon.Create(AOWner: TComponent);
var posicion : TPoint; begin //dfalñkds
inherited Create(AOWner);
FTag:=0;
caption:='';
width := 75;
height:= 16;
bevelouter := bvNone;
posicion.X := Left;
posicion.Y := Top;
Big := TSpeedButton.create(Self);
Big.Parent := Self;
big.ClientToParent(posicion);
big.Flat := True;
Big.Width := width;
Big.Height := Height;
Small := TSpeedButton.Create(Self);
Small.Parent := Self;
small.ClientToParent(posicion);
small.Flat := True;
small.Width := big.Height div 2;
small.Height := big.Height;
small.Top := big.Top;
small.Left := left + width - small.Width;
BigCaption:=FBigLabel;
small.NumGlyphs:=1;
big.NumGlyphs:=1;
caption:='';
resize;

end;
procedure TPButon.Resize;
begin inherited;
caption:='';
big.Height := height;
big.Width := width;
small.Width := big.Height div 2 + 2;
small.Height := big.Height;
small.Top:=big.Top;
small.Left := big.Left + big.Width - small.Width;

end;

destructor TPButon.Destroy;
begin big.Free; small.Free; inherited;
end;

end.


y luego cuando utilizo en mi programa el tpanel(sender) no hace caso imagino por que yo estoy utlizando el sender del bigonclick y no el del panel

gracias de antemano

eduarcol
14-06-2008, 14:37:31
si sabes que el sender te devuelve especificamente esta clase podrias hacer algo como:

TPanel(TSpeedButton(Sender).Parent)

madmai
14-06-2008, 16:46:34
muchas gracias me ha funcionado tengo que perfeccionar cosas en el programa pero era lo que queria otra vez gracias.

madmai
15-06-2008, 02:39:59
Como podria añadirle la propiedad transparent al panel gracias de antemano?