Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitMyItemMenu;
- interface
- uses
- SysUtils, Classes, Graphics, Buttons, StdCtrls, ExtCtrls, Controls,
- Types,Messages, Dialogs;
- type
- TShapeEnum = (pLeft, pBottom);
- TMyItemMenu = class(TCustomControl)
- private
- Panel_Fundo : TPanel;
- Shape_Lateral : TShape;
- Image_Menu_Item : TImage;
- Label_Menu_Item : TLabel;
- FShapeWidth : Integer;
- FShapeHeight : Integer;
- FShapeColor : TColor;
- FShapePosicion : TShapeEnum;
- FPanelColor : TColor;
- FPanelOverColor : TColor;
- FPanelColorSelected : TColor;
- FPanelSelected : Boolean;
- FTextMenu : String;
- FTextMenuFont : TFont;
- FImagem : TPicture;
- FImagemWidth : Integer;
- FOnMouseEnter : TNotifyEvent;
- FOnClick: TNotifyEvent;
- procedure configuracao;
- procedure SetTextMenu(const Value: string);
- procedure SetImagem(const Value: TPicture);
- procedure SetPanelColor(const Value: TColor);
- procedure SetPanelOverColor(const Value: TColor);
- procedure SetShapeColor(const Value: TColor);
- procedure SetShapeWidth(const Value: Integer);
- procedure SetTextMenuFont(const Value: TFont);
- procedure Paint; override;
- procedure SetPanelColorOver(const Value: TColor);
- procedure SetImagemWidth(const Value: Integer);
- procedure SetPicture(const Value: TPicture);
- procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
- procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
- procedure MouseEnterColor;
- procedure MouseMouseLeave;
- procedure SetShapePosicion(const Value: TShapeEnum);
- procedure SetShapeHeight(const Value: Integer);
- procedure SetPanelColorSelected(const Value: TColor);
- procedure SetPanelSelected(const Value: Boolean);
- procedure SetOnClick(const Value: TNotifyEvent);
- procedure Click(Sender: TObject);
- protected
- procedure CreateWnd; override;
- public
- constructor Create(aOwner : TComponent); override;
- destructor Destroy; override;
- procedure LoadFromFile(const Filename: string);
- published
- property ShapeWidth : Integer read FShapeWidth write SetShapeWidth;
- property ShapeHeight : Integer read FShapeHeight write SetShapeHeight;
- property ShapeColor : TColor read FShapeColor write SetShapeColor;
- property ShapePosicion : TShapeEnum read FShapePosicion write SetShapePosicion;
- property PanelColor : TColor read FPanelColor write SetPanelColor;
- property PanelColorOver : TColor read FPanelOverColor write SetPanelColorOver;
- property PanelColorSelected : TColor read FPanelColorSelected write SetPanelColorSelected;
- property PanelSelected : Boolean read FPanelSelected write SetPanelSelected;
- property TextMenuFont : TFont read FTextMenuFont write SetTextMenuFont;
- property Imagem : TPicture read FImagem write SetImagem;
- property ImagemWidth : Integer read FImagemWidth write SetImagemWidth;
- property Picture: TPicture read FImagem write SetPicture;
- property TextMenu : string read FTextMenu write SetTextMenu;
- property OnClick : TNotifyEvent read FOnClick write SetOnClick; //evento definido no object inspector
- end;
- procedure register;
- implementation
- procedure register;
- begin
- registercomponents('My Componentes', [TMyItemMenu]);
- end;
- constructor TMyItemMenu.Create(aOwner : TComponent);
- begin
- inherited Create(aOwner);
- self.Width:=200;
- self.Height:=40;
- self.ParentColor:=True;
- FPanelColor := self.Color;
- FPanelOverColor:=self.Color;
- Panel_Fundo := TPanel.Create(self);
- Panel_Fundo.Parent:= self;
- Panel_Fundo.ParentColor:= True;
- //Panel_Fundo.Color:=FPanelColor;
- Shape_Lateral := TShape.Create(Panel_Fundo);
- Shape_Lateral.Parent:= Panel_Fundo.Parent;
- Shape_Lateral.Align:=alLeft;
- FShapeWidth :=3; //valor definido como defaul
- FShapeHeight:=3;
- FImagem := TPicture.Create;
- Image_Menu_item := TImage.Create(Panel_Fundo);
- Image_Menu_item.parent:= Panel_Fundo.Parent;
- FTextMenuFont := TFont.Create;
- Label_Menu_Item := TLabel.Create(Panel_Fundo);
- Label_Menu_Item.parent:= Panel_Fundo.Parent;
- Label_Menu_Item.Font:= FTextMenuFont;
- configuracao;
- end;
- procedure TMyItemMenu.CreateWnd;
- begin
- inherited;
- FPanelColor := self.Color;
- Image_Menu_item.Picture:=FImagem;
- Label_Menu_Item.Font:=FTextMenuFont;
- //Label_Menu_Item.Transparent:=True;
- Label_Menu_Item.Font:=FTextMenuFont;
- Label_Menu_Item.Color:=FPanelColor;
- //
- Panel_Fundo.OnClick:=self.OnClick;
- Label_Menu_Item.OnClick:=self.OnClick;
- Image_Menu_item.OnClick:=self.OnClick;
- //OnMouseEnter
- Panel_Fundo.OnMouseEnter:=self.OnMouseEnter;
- Label_Menu_Item.OnMouseEnter:=self.OnMouseEnter;
- Image_Menu_item.OnMouseEnter:=self.OnMouseEnter;
- //OnMouseLeave
- Panel_Fundo.OnMouseLeave:=self.OnMouseLeave;
- Label_Menu_Item.OnMouseLeave:=self.OnMouseLeave;
- Image_Menu_item.OnMouseLeave:=self.OnMouseLeave;
- end;
- destructor TMyItemMenu.Destroy;
- begin
- inherited;
- end;
- procedure TMyItemMenu.LoadFromFile(const Filename: string);
- begin
- Image_Menu_item.Picture.LoadFromFile(Filename);
- Image_Menu_item.Refresh;
- end;
- procedure TMyItemMenu.MouseEnterColor;
- begin
- end;
- procedure TMyItemMenu.MouseMouseLeave;
- begin
- end;
- procedure TMyItemMenu.Paint;
- begin
- with Canvas do
- begin
- ///usar aqui para desenhar algo novo no componente
- end;
- end;
- procedure TMyItemMenu.SetImagem(const Value: TPicture);
- begin
- FImagem.Assign(Value);
- Image_Menu_item.Picture:=FImagem;
- Image_Menu_item.Refresh;
- end;
- procedure TMyItemMenu.SetImagemWidth(const Value: Integer);
- begin
- FImagemWidth := Value;
- Image_Menu_item.Width:=FImagemWidth;
- end;
- procedure TMyItemMenu.SetOnClick(const Value: TNotifyEvent);
- begin
- FOnClick := Value;
- Self.OnClick:= Click;
- end;
- procedure TMyItemMenu.SetPanelColor(const Value: TColor);
- begin
- FPanelColor := Value;
- self.ParentColor:=False;
- self.Color:=FPanelColor;
- Label_Menu_Item.Transparent:=False;
- Panel_Fundo.Color:=FPanelColor;
- Label_Menu_Item.Color:=FPanelColor;
- end;
- procedure TMyItemMenu.SetPanelColorOver(const Value: TColor);
- begin
- FPanelOverColor := Value;
- end;
- procedure TMyItemMenu.SetPanelColorSelected(const Value: TColor);
- begin
- FPanelColorSelected := Value;
- end;
- procedure TMyItemMenu.SetPanelOverColor(const Value: TColor);
- begin
- FPanelOverColor := Value;
- end;
- procedure TMyItemMenu.SetPanelSelected(const Value: Boolean);
- begin
- FPanelSelected := Value;
- end;
- procedure TMyItemMenu.SetPicture(const Value: TPicture);
- begin
- FImagem.Assign(Value);
- Image_Menu_item.Picture:=FImagem;
- Image_Menu_item.Refresh;
- end;
- procedure TMyItemMenu.SetShapeColor(const Value: TColor);
- begin
- FShapeColor := Value;
- Shape_Lateral.Brush.Color:=FShapeColor;
- Shape_Lateral.Pen.Color:=FShapeColor;
- end;
- procedure TMyItemMenu.SetShapeHeight(const Value: Integer);
- begin
- FShapeHeight := Value;
- Shape_Lateral.Height:=FShapeHeight;
- end;
- procedure TMyItemMenu.SetShapePosicion(const Value: TShapeEnum);
- begin
- FShapePosicion := Value;
- case Value of
- pLeft:
- begin
- Shape_Lateral.Align:=alLeft;
- Shape_Lateral.Height:=0;
- end;
- pBottom:
- begin
- Shape_Lateral.Align:=alBottom;
- Shape_Lateral.Height:=FShapeHeight;
- end;
- end;
- end;
- procedure TMyItemMenu.SetShapeWidth(const Value: Integer);
- begin
- FShapeWidth := Value;
- Shape_Lateral.Width:=FShapeWidth;
- end;
- procedure TMyItemMenu.SetTextMenu(const Value: string);
- begin
- FTextMenu := Value;
- Label_Menu_Item.Caption:=FTextMenu;
- end;
- procedure TMyItemMenu.SetTextMenuFont(const Value: TFont);
- begin
- FTextMenuFont.Assign(Value);
- Label_Menu_Item.Font:=FTextMenuFont;
- end;
- procedure TMyItemMenu.Click(Sender: TObject);
- begin
- FPanelSelected:=True;
- self.ParentColor:=False;
- self.Color:=FPanelColorSelected;
- Label_Menu_Item.Transparent:=False;
- Panel_Fundo.Color:=FPanelColorSelected;
- Label_Menu_Item.Color:=FPanelColorSelected;
- end;
- procedure TMyItemMenu.CMMouseEnter(var Message: TMessage);
- begin
- inherited;
- Shape_Lateral.Brush.Color:=FShapeColor;
- Shape_Lateral.Pen.Color:=FShapeColor;
- Self.Color:= FPanelOverColor;
- end;
- procedure TMyItemMenu.CMMouseLeave(var Message: TMessage);
- begin
- inherited;
- Shape_Lateral.Brush.Color:=FPanelColor;
- Shape_Lateral.Pen.Color:=FPanelColor;
- Self.Color:= FPanelColor;
- end;
- procedure TMyItemMenu.configuracao;
- begin
- Panel_Fundo.Align:=alClient;
- Panel_Fundo.BevelOuter:=bvNone;
- Panel_Fundo.ParentColor:=True;
- ////
- FShapeColor := clRed;
- Shape_Lateral.width:=8;
- Shape_Lateral.Align:=alLeft;
- Shape_Lateral.Brush.Color:=FShapeColor;
- Shape_Lateral.Pen.Style:=psSolid;
- Shape_Lateral.Pen.Color:=FShapeColor;
- Shape_Lateral.Width:=FShapeWidth;
- ////
- FImagemWidth:=38;
- Image_Menu_item.width:=FImagemWidth;
- Image_Menu_item.Align:=alLeft;
- Image_Menu_item.Stretch:=True;
- ////
- FTextMenu:='Teste de Texto';
- FTextMenuFont.Name:='Segoe UI';
- FTextMenuFont.Size:=11;
- Label_Menu_Item.width:=100;
- Label_Menu_Item.Align:=alLeft;
- Label_Menu_Item.Caption:=FTextMenu;
- Label_Menu_Item.Layout:=tlCenter;
- Label_Menu_Item.Font.Size:=FTextMenuFont.Size;
- Label_Menu_Item.Font.Name:=FTextMenuFont.Name;
- Label_Menu_Item.ParentColor:=True;
- Label_Menu_Item.Transparent:=True;
- Label_Menu_Item.Color:=FPanelColor;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement