Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Для новичков > Создание компонента


Автор: cSKA 28.11.2007, 21:53
Кто нибудь помогите мне надо создать компонет так чтобы он включал в себя поле Handle  поле Transparent 
подскажите что-нибудь
я сделал компонет потомок от TCustomControl и вписал в него поле Transparent из сорсов поставки Delphi7 но ничего не вышло компонет не прозрачен 
что делать?

Автор: aktuba 28.11.2007, 22:46
Цитата(cSKA @  28.11.2007,  22:53 Найти цитируемый пост)
что делать? 

Отрисовывать в ручную  smile 
При чем тут поле в классе???

Автор: THandle 28.11.2007, 23:19
Может стоит почитать для начала книжечку. Например Рея Конопку?

Автор: ivan219 29.11.2007, 10:41
cSKA, Transparent это прозрачный цвет или отсутствие фона.
P.S. Handle там уже есть так как это наследние от TWinControl в котором Handle и появляется.

Код

unit FCustomControl;

interface

uses
  SysUtils, Classes, Controls, Graphics;

type
  TFCustomControl = class(TCustomControl)
  private
    FTransparent: Boolean;
  protected
    procedure SetTransparent(Value: Boolean);
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Transparent: Boolean read FTransparent write SetTransparent default False;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('MyComponent', [TFCustomControl]);
end;

{ TFCustomControl }

constructor TFCustomControl.Create(AOwner: TComponent);
begin
  inherited;
  FTransparent := False;
end;

procedure TFCustomControl.Paint;
begin
  inherited;
  if not FTransparent then
   begin
    Canvas.Brush.Color := clRed;
    Canvas.FillRect(ClientRect);
   end;
end;

procedure TFCustomControl.SetTransparent(Value: Boolean);
begin
  if FTransparent <> Value then
   begin
    FTransparent := Value;
    Invalidate;
   end; 
end;

end.

Автор: cSKA 1.12.2007, 23:50
я все понимаю только то что ты описал я попробовал и это не сработало
я также пробавал код из сорсов от TCustomLabel
я много читаю и нигду не встречал компонентов содержащих одновременно Handle и Transparent

Автор: ivan219 4.12.2007, 15:39
Цитата(cSKA @  1.12.2007,  23:50 Найти цитируемый пост)
я все понимаю только то что ты описал я попробовал и это не сработало

Цитата(ivan219 @  29.11.2007,  10:41 Найти цитируемый пост)
Transparent это прозрачный цвет

но можно и так
Цитата(ivan219 @  29.11.2007,  10:41 Найти цитируемый пост)
 или отсутствие фона.

что я и продемонстрировал тебе.
Цитата(cSKA @  1.12.2007,  23:50 Найти цитируемый пост)
я много читаю и нигду не встречал компонентов содержащих одновременно Handle и Transparent

Плохо читал!
Что для тебя озночает слово Handle???




Автор: cSKA 11.12.2007, 18:13
под Handle Я понимаю свойство Handle: HWND!!!
не работает то что ты предлагаешь
я не такой дурак чтоб незнать что Handle появляется в TWinControl а все компоненты с полем Transparent  идут от TGraphicControl в котором как всем известно Handle нет
мне нужно создать компонент имеющий оба эти поля

я хорошо читаю просто мало книг на нестандартные методы программирования

Автор: ivan219 11.12.2007, 23:28
Цитата(cSKA @  11.12.2007,  18:13 Найти цитируемый пост)
Я понимаю свойство Handle: HWND!!!

Это радует.
Цитата(cSKA @  11.12.2007,  18:13 Найти цитируемый пост)
а все компоненты с полем Transparent  идут от TGraphicControl

TGroupBox хоть и нет явного свойства Transparent аднако если подцепить XPManifest  оно проявляется smile 

Автор: ivan219 12.12.2007, 00:09
Код

unit FLabel;

interface

uses
  SysUtils, Classes, Controls, Graphics;

type
  TFLabel = class(TCustomControl)
  private
    FTransparent: Boolean;
    FText: String;
  protected
    procedure Paint; override;
    procedure SetText(const Value: String); virtual;
    procedure SetTransparent(const Value: Boolean); virtual;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Text: String read FText write SetText;
    property Transparent: Boolean read FTransparent write SetTransparent Default False;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('MyComponent', [TFLabel]);
end;

{ TFLabel }

constructor TFLabel.Create(AOwner: TComponent);
begin
  inherited;
  Width := 32;
  Height := 13;
  FText := 'FLabel';
  FTransparent := False;
end;

procedure TFLabel.SetText(const Value: String);
begin
 if FText <> Value then
  begin
   FText := Value;
   Width := Canvas.TextWidth(FText);
   Height := Canvas.TextHeight(FText);
   Invalidate;
  end;
end;

procedure TFLabel.SetTransparent(const Value: Boolean);
begin
 if FTransparent <> Value then
  begin
   FTransparent := Value;
   if FTransparent then Canvas.Brush.Style := bsClear
   else Canvas.Brush.Style := bsSolid;
   Invalidate;
  end;
end;

procedure TFLabel.Paint;
begin
  inherited;
  Canvas.TextOut(0,0,FText);
end;
end.

Код

unit FLabel;

interface

uses
  Messages, SysUtils, Classes, Controls, Graphics;

type
  TFLabel = class(TCustomControl)
  private
    FTransparent: Boolean;
  protected
    procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
    procedure Paint; override;
    procedure SetTransparent(const Value: Boolean); virtual;
  public
    constructor Create(AOwner: TComponent); override;
    property Handle;
  published
    property Caption;
    property Transparent: Boolean read FTransparent write SetTransparent Default False;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('MyComponent', [TFLabel]);
end;

{ TFLabel }

constructor TFLabel.Create(AOwner: TComponent);
begin
  inherited;
  Width := 32;
  Height := 13;
  Caption := 'FLabel';
  FTransparent := False;
end;

procedure TFLabel.CMTextChanged(var Message: TMessage);
begin
  Invalidate;
  Realign;
end;

procedure TFLabel.SetTransparent(const Value: Boolean);
begin
 if FTransparent <> Value then
  begin
   FTransparent := Value;
   if FTransparent then Canvas.Brush.Style := bsClear
   else Canvas.Brush.Style := bsSolid;
   Invalidate;
  end;
end;

procedure TFLabel.Paint;
begin
  inherited;
  Width := Canvas.TextWidth(Text);
  Height := Canvas.TextHeight(Text);  
  Canvas.TextOut(0,0,Text);
end;
end.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)