Bir bileşen yazmak istiyorum, bu bileşen standart bir buton olacak fakat ekstradan TControl türünde seçtiğim bir nesneyi de kendisine bağlayacak.
Bu butona bastığımda o butonun hemen altında TControl'e atadığım bileşeni göstermek, bileşenden çıktığımda ise o bileşenin gizlenmesini sağlayacak.
Property olarak bir TControl'ü bileşene ekledim. Tıklandığında atadığım TControl'ü de gösteriyor fakat TControl'den çıktığımda TControl OnExit olayını tetiklemiyor,
Bu sorunu nasıl aşarım, nasıl çözerim?
Örnek teşkil etmesi açısından aşağıda kodları veriyorum;
Derdimi tam anlatamadım gibime geliyor o nedenle kaynak kodları da paylaşıyorum,
Kod: Tümünü seç
unit Unit1;
interface
uses
Winapi.Windows, System.Classes,
Vcl.Controls, Vcl.Forms,
Vcl.ExtCtrls, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Label11: TLabel;
Label12: TLabel;
procedure Button1Click(Sender: TObject);
procedure aControlOnExitOlayi(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Kontrolu_Goster(aControl: TControl; _Control: TControl);
var
P : TPoint;
begin
P := Point( aControl.Left
, aControl.Top
+ aControl.Height
);
_Control.SetBounds( P.X
, P.Y
, _Control.Width
, _Control.Height
);
//_Control.Visible := True;
_Control.Show;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Kontrolu_Goster(TControl(Sender), Panel1);
end;
procedure TForm1.aControlOnExitOlayi(Sender: TObject);
begin
TControl(Sender).Hide;
end;
end.
Kod: Tümünü seç
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 504
ClientWidth = 852
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 18
Top = 18
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object Panel1: TPanel
Left = 18
Top = 61
Width = 489
Height = 86
TabOrder = 1
Visible = False
OnExit = aControlOnExitOlayi
object Label11: TLabel
Left = 22
Top = 16
Width = 37
Height = 13
Caption = 'Label11'
end
object Label12: TLabel
Left = 22
Top = 44
Width = 413
Height = 13
Caption =
'Bu panelin d'#305#351#305'na t'#305'kland'#305#287#305'nda VEYA ba'#351'ka bir nesneye ge'#231'ildi'#287'i' +
'nde bu panel gizlenecek'
end
end
end