Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.05.07;
Скачать: CL | DM;

Вниз

TIcon + TLabel   Найти похожие ветки 

 
forgery ©   (2005-10-29 23:07) [0]

Скрещиваю TCustomLabel и TImage, на пример TLabeledEdit, в результате все нормально, но есть проблемы при Align в состоянии не alNone. В положении alLeft и alTop, проблем нет при изменении размера формы а вот в alClient, alRight, alBottom наблюдается непонятное перемещение компонента по основной форме.
Перемещение делаю перерисовывая привязанный имаг, перекрывая у лабела родительский метод:

 { TCustomImagedLabel }
 TCustomImagedLabel = class(TCustomlabel)
 private
   FLabelImage: TBoundImage;
   FImagePosition: TImagePosition;
   FImageSpacing: Integer;
   procedure SetImagePosition(const Value: TImagePosition);
   procedure SetImageSpacing(const Value: Integer);
 protected
   procedure SetParent(AParent: TWinControl); override;
   procedure Notification(AComponent: TComponent; Operation: TOperation); override;
   procedure CMVisiblechanged(var Message: TMessage);
     message CM_VISIBLECHANGED;
   procedure CMEnabledchanged(var Message: TMessage);
     message CM_ENABLEDCHANGED;
 public
   constructor Create(AOwner: TComponent); override;
   procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
   procedure SetupInternalLabel;
   property LabelImage: TBoundImage read FLabelImage;
   property ImagePosition: TImagePosition read FImagePosition write SetImagePosition;
   property ImageSpacing: Integer read FImageSpacing write SetImageSpacing;
 end;

procedure TCustomImagedLabel.SetBounds(ALeft, ATop, AWidth,
 AHeight: Integer);
var
 sign: Integer;
begin
 if (FImagePosition in [ipTop]) then begin
   if (Align in [alTop]) then begin
     ATop:=ATop+FLabelImage.Height+FImageSpacing;
   end;
   if (Align in [alClient]) then begin
     ATop:=ATop+FLabelImage.Height+FImageSpacing;
     AHeight:=AHeight-FLabelImage.Height-FImageSpacing;
   end;
 end;

 if (FImagePosition in [ipBottom]) then begin
   if (Align in [alBottom]) then begin
     ATop:=ATop-FLabelImage.Height-FImageSpacing;
   end;
   if (Align in [alClient]) then begin
     AWidth:=AWidth-FLabelImage.Width-FImageSpacing;
   end;
 end;

 if (FImagePosition in [ipLeft]) then begin
   if (Align in [alLeft]) then begin
     ALeft:=ALeft+FLabelImage.Width+FImageSpacing;
   end;
   if (Align in [alClient]) then begin
     ALeft:=ALeft+FLabelImage.Width+FImageSpacing;
     AWidth:=AWidth-FLabelImage.Width-FImageSpacing;
   end;
 end;

 if (FImagePosition in [ipRight]) then begin
   if (Align in [alRight]) then begin
     ALeft:=ALeft-FLabelImage.Width-FImageSpacing;
   end;
   if (Align in [alClient]) then begin
     AWidth:=AWidth-FLabelImage.Width-FImageSpacing;
   end;
 end;

 inherited SetBounds(ALeft, ATop, AWidth, AHeight);
 SetImagePosition(FImagePosition);
end;

procedure TCustomImagedLabel.SetImagePosition(const Value: TImagePosition);
var
 P: TPoint;
begin
 if FLabelImage = nil then exit;
 FImagePosition := Value;
 case Value of
   ipTop   : P := Point(Left, Top - FLabelImage.Height - FImageSpacing);
   ipBottom: P := Point(Left, Top + Height + FImageSpacing);
   ipLeft  : P := Point(Left - FLabelImage.Width - FImageSpacing,
                   Top + ((Height - FLabelImage.Height) div 2));
   ipRight : P := Point(Left + Width + FImageSpacing,
                   Top + ((Height - FLabelImage.Height) div 2));
 end;
 FLabelImage.SetBounds(P.x, P.y, FLabelImage.Width, FLabelImage.Height);
end;


 
TStas ©   (2005-10-30 19:19) [1]

Align in [alClient] ? А не наоборот? И компилятор не ругается?


 
forgery ©   (2005-10-31 19:58) [2]

нет, все ок....
но вопрос то не в этом :((



Страницы: 1 вся ветка

Текущий архив: 2006.05.07;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.039 c
2-1145463720
@gent
2006-04-19 20:22
2006.05.07
Помогите пожалуйста. Фрейм не могу добавить


1-1143466199
DelphiLexx
2006-03-27 17:29
2006.05.07
Не работает DoubleBuffered при включенной тема Windows XP


4-1139733773
Alextp
2006-02-12 11:42
2006.05.07
Контекстное меню Проводника


15-1145020496
default
2006-04-14 17:14
2006.05.07
Перевод mp3 в mmf


15-1144737138
Тульский
2006-04-11 10:32
2006.05.07
Лимон на подоконнике