|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
решил попробывать не создавать отдельный компонент, а обращаться к созданию кнопки, а
решил попробывать не создавать отдельный компонент, а обращаться к созданию кнопки, а точнее её цвету.
Код:
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons; { } type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); private { Private declarations } FCanvas: TCanvas; IsFocused: Boolean; F3DFrame: boolean; FButtonColor: TColor; procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM; procedure DrawButtonText(const Caption: string; TRC: TRect; State: TButtonState; BiDiFlags: Longint); public { Public declarations }end; procedure TForm1.FormCreate(Sender: TObject); begin Button1.CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;//ругается тут end; procedure TForm1.CNDrawItem(var Message: TWMDrawItem); var RC: TRect; Flags: Longint; State: TButtonState; IsDown, IsDefault: Boolean; DrawItemStruct: TDrawItemStruct; begin DrawItemStruct := Message.DrawItemStruct^; FCanvas.Handle := DrawItemStruct.HDC; RC := ClientRect; with DrawItemStruct do begin IsDown := ItemState and ODS_SELECTED <> 0; IsDefault := ItemState and ODS_FOCUS <> 0; if not Enabled then State := bsDisabled else if IsDown then State := bsDown else State := bsUp; end; Flags := DFCS_BUTTONPUSH or DFCS_ADJUSTRECT; if IsDown then Flags := Flags or DFCS_PUSHED; if DrawItemStruct.ItemState and ODS_DISABLED <> 0 then Flags := Flags or DFCS_INACTIVE; if IsFocused or IsDefault then begin FCanvas.Pen.Color := clWindowFrame; FCanvas.Pen.Width := 1; FCanvas.Brush.Style := bsClear; FCanvas.Rectangle(RC.Left, RC.Top, RC.Right, RC.Bottom); InflateRect(RC, -1, -1); end; if IsDown then begin FCanvas.Pen.Color := clBtnShadow; FCanvas.Pen.Width := 1; FCanvas.Rectangle(RC.Left, RC.Top, RC.Right, RC.Bottom); InflateRect(RC, -1, -1); if F3DFrame then begin FCanvas.Pen.Color := FButtonColor; FCanvas.Pen.Width := 1; DrawFrameControl(DrawItemStruct.HDC, RC, DFC_BUTTON, Flags); end; end else DrawFrameControl(DrawItemStruct.HDC, RC, DFC_BUTTON, Flags); FCanvas.Brush.Color := FButtonColor; FCanvas.FillRect(RC); InflateRect(RC, 1, 1); if IsFocused then begin RC := ClientRect; InflateRect(RC, -1, -1); end; FCanvas.Font := Self.Font; if IsDown then OffsetRect(RC, 1, 1); DrawButtonText(Caption, RC, State, 0); if IsFocused and IsDefault then begin RC := ClientRect; InflateRect(RC, -4, -4); FCanvas.Pen.Color := clWindowFrame; Windows.DrawFocusRect(FCanvas.Handle, RC); end; FCanvas.Handle := 0; end; |
#2
|
||||
|
||||
Исправить просто, прочитать как создаются и наследуются компоненты или всё-таки взять готовый.
Je venus de nulle part 55.026263 с.ш., 73.397636 в.д. |
#3
|
||||
|
||||
Цитата:
и правильно делает. Даже не зная, как пишутся компоненты, как до такого можно было додуматься?! |