Pues continué experimentando con TSelectOnRuntime de Neftali en
el ejemplo del restaurante y logre adicionar la etiqueta y resaltar el TImage con un TShape
Le agregue esto al procedimiento de crear las mesa (_CreateMesa) para asociarle la etiqueta
Código Delphi
[-] lblDisp:=CrearLabelAsociada(img, NewName);
img.Hint:=lblDisp.Name;
quedando de esta forma
Código Delphi
[-]function TFormMain._CreateMesa(AName:String; AParent:TWinControl; ALeft, ATop:Integer):TImage;
var
img :TImage;
comp :TComponent;
NewName, TitDisp :String;
begin
img := TImage.Create(Self);
Result := img;
with img do
begin
Picture := imgMesaDemo.Picture;
if (AName <> '') then
begin
NewName := AName;
end
else
begin
NewName := 'Mesa_' + IntToStr(_nmesas);
comp := Self.FindComponent(NewName);
while Assigned(comp) do
begin
_nmesas := _nmesas + 1;
NewName := 'Mesa_' + IntToStr(_nmesas);
comp := Self.FindComponent(NewName);
end;
end;
_nmesas := _nmesas + 1;
Parent := AParent;
img.Name := NewName;
img.ShowHint := True;
img.Hint := 'Mesa: ' + img.Name;
Left := ALEft;
Top := ATop;
height := imgMesaDemo.Height;
width := imgMesaDemo.Width;
Transparent := True;
Stretch := True;
OnClick := OnMesaClick;
lblDisp:=CrearLabelAsociada(img, NewName);
img.Hint:=lblDisp.Name;
cbMesa.Items.Add(NewName);
cbMesa.ItemIndex := 0;
cbMesa2.Items.Add(NewName);
cbMesa2.ItemIndex := 0;
end;
end;
Estab es la funcion del Label
Código Delphi
[-]function TFormMain.CrearLabelAsociada(AImage: TImage; Titulo: string):TLabel;
var
lbl :TLabel;
begin
Randomize;
lbl:=TLabel.Create(Self);
with lbl do
begin
Name:='lblRed'+IntToStr(Random(1000));
Parent:=AImage.Parent;
Left:=AImage.Left;
Top:=AImage.Top + AImage.Height + 2;
Caption:=Titulo;
Alignment:=taCenter;
end;
Result:=lbl;
end;
Y para el resaltado modifique el evento OnMesaClick, quedando de esta forma
Código Delphi
[-]procedure TFormMain.OnMesaClick(Sender: TObject);
begin
SelectOnRunTime.Selected := False;
if (Sender is TControl) then
begin
SelectOnRunTime.SelectControl:=TControl(Sender);
SelectOnRunTime.Selected:=True;
shp1.Visible:=True;
shp1.Left:=TControl(Sender).Left-1;
shp1.Top:=TControl(Sender).Top-1;
lblDisp:=TLabel(FindComponent(TControl(Sender).Hint));
lblDisp.Left:=TControl(Sender).Left;
lblDisp.Top:=TControl(Sender).Top + TControl(Sender).Height + 2;
end;
end;
Aunque me quedo un poco "rustico" ya que cuando se mueve el control, la etiqueta y el marco se quedan en su origen hasta que se suelte el control en su destino, que se ubican en la posicion correcta
Pero bueno, por ahora esta bien, despues se podra refinar un poco para que quede mejor