Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

ImageIndex [D6]


Незнайка111 ©   (2006-12-07 10:59:00) 

Как реализовать чтобі в инспекторе поле ImageIndex біло с картинками, как например в ActionList ?


DrPass   (2006-12-12 00:16:00) [1]

Все это, конечно, круто...
Но если ImageIndex - номер картинки в ImageList, достаточно будет вызвать RegisterPropertyEditor для компоненты тов. Незнайки111, указав стандартный редактор свойства ImageIndex.


ors_archangel   (2006-12-10 10:46:00) [2]

Хороший вопрос, Нейзнайка111!

Пример, тут поле типа TStartStopState (вот такой у меня тип) - это enum, имеющий два состояния (ssStart,ssStop), он отображается в инспекторе как список с иконками, можно использовать и, например, TIntegerProperty, конечно, если нужно....

||| CODE STARTS HERE |||

{$r uCombCtrlsPropEds.dcr} // тут я нарисовал две картинки, что рисовать

interface
uses Windows, Types, Graphics, DesignIntf, DesignEditors, vcleditors…;

type
{ TStartStopStateProperty
 Property editor for the TStartStopState type.
 Displays the icon and state name }
 TStartStopStateProperty = class(TEnumProperty, ICustomPropertyDrawing,
   ICustomPropertyListDrawing)
 public
   { ICustomPropertyListDrawing }
   procedure ListMeasureHeight(const Value: string; ACanvas: TCanvas;
     var AHeight: Integer);
   procedure ListMeasureWidth(const Value: string; ACanvas: TCanvas;
     var AWidth: Integer);
   procedure ListDrawValue(const Value: string; ACanvas: TCanvas;
     const ARect: TRect; ASelected: Boolean);
   { ICustomPropertyDrawing }
   procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect;
     ASelected: Boolean);
   procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
     ASelected: Boolean);
 end;

procedure Register;

implementation
uses
 Classes, TypInfo…;

procedure Register;
begin
 RegisterPropertyEditor(TypeInfo(TStartStopState), nil{any component}, ''{any name}, TStartStopStateProperty);
end;

{ TStartStopStateProperty }
procedure TStartStopStateProperty.PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
 ASelected: Boolean);
begin
 if GetVisualValue <> '' then
   ListDrawValue(GetVisualValue, ACanvas, ARect, ASelected)
 else
   DefaultPropertyDrawValue(Self, ACanvas, ARect);
end;

procedure TStartStopStateProperty.ListDrawValue(const Value: string;
 ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
var
 Right: Integer;
 OldPenColor, OldBrushColor: TColor;
 icon: HIcon;
 state: TStartStopState;
begin
 Right := (ARect.Bottom - ARect.Top) {* 2} + ARect.Left;
 with ACanvas do
 begin
   // save off things
   OldPenColor := Pen.Color;
   OldBrushColor := Brush.Color;
   // frame things
   Pen.Color := Brush.Color;
   Brush.Color := clWindow;
   Rectangle(ARect.Left, ARect.Top, right, ARect.Bottom);
   // draw icon
   state := TStartStopState(GetEnumValue(GetPropInfo^.PropType^, Value));
   case state of
   ssStart: icon := LoadIcon(HInstance, 'COMBCTRLS_STARTBTN');
   ssStop: icon := LoadIcon(HInstance, 'COMBCTRLS_STOPBTN');
   else
     icon := 0;
   end;
   //textout(0,0,value);
   DrawIconex(ACanvas.Handle, arect.Left,arect.top, icon, 16,16, 0,0, DI_NORMAL);
   //DrawIcon(ACanvas.Handle, arect.left,arect.top, icon);
   DeleteObject(icon);
   // restore the things we twiddled with
   Brush.Color := OldBrushColor;
   Pen.Color := OldPenColor;
   DefaultPropertyListDrawValue(Value, ACanvas,
     Rect(right, ARect.Top, ARect.Right, ARect.Bottom), ASelected);
 end;
end;

procedure TStartStopStateProperty.ListMeasureWidth(const Value: string;
 ACanvas: TCanvas; var AWidth: Integer);
begin
 AWidth := AWidth + ACanvas.TextHeight('A') {* 2};
end;

procedure TStartStopStateProperty.ListMeasureHeight(const Value: string;
 ACanvas: TCanvas; var AHeight: Integer);
begin
 // No implementation necessary
end;

procedure TStartStopStateProperty.PropDrawName(ACanvas: TCanvas;
 const ARect: TRect; ASelected: Boolean);
begin
 DefaultPropertyDrawName(Self, ACanvas, ARect);
end;

||| END OF CODE |||

Собственно я тут только часть метода ListDrawValue, остальное просто скопировал из стандартных исходников, подробнее смотри Delphi Help: Component Writers Guide / Making Components available at design time / Adding property editors  и  Delphi 7/Source/Tools API/VCLEditors.pas и др.

Удачи всем в создании своих компонентов!


Наверх

Титульная страница Поиск, карта сайта Написать письмо