Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UMyComboBox;
- interface
- uses
- SysUtils, Classes, Controls, StdCtrls, Buttons, Forms,
- Graphics, Dialogs, ExtCtrls, Windows, Grids;
- type
- TMyComboBox = class(TCustomControl)
- private
- MyEditCombo : TEdit;
- MyButtomCombo : TSpeedButton;
- MyEditPesquisar : TEdit;
- MyFrame : TFrame;
- MyPanel : TPanel;
- MyShape : TShape;
- MyStringGrid : TStringGrid;
- FPanelColor : TColor;
- FCampos : TStringList;
- procedure AbrirBox(Sender: TObject);
- procedure Pesquisar(Sender: TObject);
- procedure Selecionar(Sender: TObject);
- procedure KeyPress(Sender: TObject; var Key: Char);
- procedure SetPanelColor(const Value: TColor);
- procedure SetCampos(const Value: TStringList);
- procedure ConfigurarStringGrid;
- protected
- procedure CreateWnd; override;
- public
- constructor Create(aOwner : TComponent); override;
- destructor Destroy; override;
- published
- property PanelColor : TColor read FPanelColor write SetPanelColor;
- property Campos : TStringList read FCampos write SetCampos;
- end;
- procedure register;
- implementation
- procedure register;
- begin
- registercomponents('My Componentes', [TMyComboBox]);
- end;
- { TMyComboBox }
- constructor TMyComboBox.Create(aOwner: TComponent);
- begin
- inherited Create(AOwner);
- self.Width:=200;
- self.Height:=21;
- self.ParentColor:=True;
- MyEditCombo:=TEdit.Create(self);
- MyEditCombo.Parent:=Self;
- MyEditCombo.Width:=180;
- MyEditCombo.Anchors:=[akLeft,akRight,akTop, akBottom];
- MyButtomCombo := TSpeedButton.Create(self);
- MyButtomCombo.Parent:=self;
- MyButtomCombo.Width:=20;
- MyButtomCombo.Height:=MyEditCombo.Height+4;
- MyButtomCombo.Top:=MyEditCombo.Top-1;
- MyButtomCombo.Left:=MyEditCombo.Width+1;
- MyButtomCombo.Anchors:=[akRight,akTop, akBottom];
- MyButtomCombo.OnClick:=AbrirBox;
- FCampos := TStringList.Create;
- end;
- procedure TMyComboBox.CreateWnd;
- begin
- inherited CreateWnd;
- end;
- procedure TMyComboBox.AbrirBox(Sender: TObject);
- begin
- if assigned(MyFrame) then
- if MyFrame.Visible=True then
- begin
- MyFrame.Visible:=False;
- exit;
- end;
- MyFrame := TFrame.Create(nil);
- MyFrame.Parent:= Parent;
- MyFrame.Name:= 'CustomFrame';
- MyFrame.Width:=400;
- MyFrame.Height:=250;
- MyFrame.Top:=self.Top+self.Height;
- MyFrame.Left:=self.Left;
- MyFrame.Visible:=True;
- MyPanel := TPanel.Create(nil);
- MyPanel.Parent:= MyFrame;
- MyPanel.Name:= 'CustomPanel';
- MyPanel.Caption:= 'Nenhum Registro Encontrado !';
- MyPanel.Align:= alClient;
- MyPanel.ParentBackground:= False;
- MyPanel.Color:= clYellow;
- MyPanel.Visible:= True;
- MyStringGrid := TStringGrid.Create(nil);
- MyStringGrid.Parent := MyPanel;
- MyStringGrid.Name := 'CustomStringGrid';
- MyStringGrid.Align:= alTop;
- MyStringGrid.Height:= 200;
- MyStringGrid.BorderStyle:= bsNone;
- MyStringGrid.OnDblClick:=Selecionar;
- ConfigurarStringGrid;
- MyShape := TShape.Create(nil);
- MyShape.Parent := MyPanel;
- MyShape.Name := 'CustomShape';
- MyShape.Align:= alTop;
- MyShape.Height:= 2;
- MyEditPesquisar := TEdit.Create(nil);
- MyEditPesquisar.Parent := MyPanel;
- MyEditPesquisar.Name := 'CustomEdit';
- MyEditPesquisar.Text := 'Pesquisar';
- MyEditPesquisar.Align:= alTop;
- MyEditPesquisar.Font.Name:= 'Segoe UI';
- MyEditPesquisar.Font.Size:= 11;
- MyEditPesquisar.OnChange:=Pesquisar;
- MyEditPesquisar.OnKeyPress:=KeyPress;
- MyEditPesquisar.BorderStyle:=bsNone;
- MyEditPesquisar.SetFocus;
- end;
- destructor TMyComboBox.Destroy;
- begin
- inherited;
- end;
- procedure TMyComboBox.KeyPress(Sender: TObject; var Key: Char);
- begin
- if (key = #27) then
- begin
- MyFrame.Visible:=False;
- MyEditCombo.SetFocus;
- end;
- end;
- procedure TMyComboBox.Pesquisar(Sender: TObject);
- begin
- if (MyEditPesquisar.Text = '') then
- begin
- MyStringGrid.Visible:=false;
- end
- else
- begin
- MyStringGrid.Visible:=True;
- end;
- end;
- procedure TMyComboBox.Selecionar(Sender: TObject);
- begin
- MyFrame.Visible:=False;
- MyEditCombo.SetFocus;
- end;
- procedure TMyComboBox.SetCampos(const Value: TStringList);
- begin
- FCampos := Value;
- end;
- procedure TMyComboBox.SetPanelColor(const Value: TColor);
- begin
- FPanelColor := Value;
- end;
- procedure TMyComboBox.ConfigurarStringGrid;
- var
- i : integer;
- begin
- { Primeira linha para o título e a segunda linha em branco }
- MyStringGrid.RowCount := 2;
- { Cria Colunas Conforme Quantidade de Itens em FCampos }
- MyStringGrid.ColCount:=FCampos.Count;
- { Preencher o titulo de cada coluna com os dados de FCampos }
- if FCampos.Count<>0 then
- begin
- for i := 0 to FCampos.Count - 1 do
- MyStringGrid.Cells[i, 0] := FCampos[i];
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement