我创建了一个复合组件,其中的基类为TCustomPanel
,后来我们在运行时在组件中创建了cxGroupBoxes
和cxCheckList
框,并设计了一个复合组件。
我们还实现了复选框列表事件的2个并发布了复选框列表组件。
我们正在尝试通过实现更多功能来在应用程序中使用这些事件。这是行不通的。任何人都可以帮助我们吗?
除面板外的所有组件均为DevExpress
组件。
更新 问题是,我已经在cxChecklistbox的onClickCheck事件中实现了全选并在组件中取消了全部选择,将组件放在窗体上之后,我想在cxchecklistbox的OnClickCheck事件中实现其他无效的代码。
组件代码如下:
unit DXCheckListBox;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, cxContainer,
cxEdit, cxCustomListBox, cxCheckListBox, cxGraphics, cxControls,
cxLookAndFeels, cxLookAndFeelPainters, cxPC, dxDockPanel, dxDockControl, Vcl.StdCtrls,
cxGroupBox, cxCheckBox, dxBevel, System.ImageList, Vcl.ImgList, Vcl.CheckLst,
cxListView, dxGDIPlusClasses, cxClasses, cxlabel;
type
TDXCheckListBox = class(TCustomPanel)
private
{Private declarations}
fGBSelectAll: TcxGroupBox;
fGBCheckList: TcxGroupBox;
fCxCheckList: TcxCheckListBox;
fDxBevel: TShape;
fCxCheckSelectAll: TcxCheckListBox;
FCaption : TCaption;
FKeys: TcxCheckListBoxItems;
FOnClickChecklist: TcxClickCheckEvent;
Procedure CheckListBoxAllCheckClick(ASender: TObject; AIndex: Integer; APrevCheckState,ANewCheckState: TcxCheckBoxState);
Procedure CheckListBoxCheckClick(ASender: TObject; AIndex: Integer; APrevCheckState,ANewCheckState: TcxCheckBoxState);
protected
{ Protected declarations }
public
{Public declarations}
constructor Create(AOwner: TComponent); override;
procedure OnDrawCheckList(AControl: TWinControl; AIndex: Integer; ARect: TRect; AState: TOwnerDrawState);
published
{ Published declarations }
property Alignment;
property Align;
property Anchors;
property BiDiMode;
property Caption: TCaption read FCaption write FCaption;
property Constraints;
property Ctl3D;
property UseDockManager;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property ParentBackground;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property CheckListHeader : TcxCheckListBox read fCxCheckSelectAll write fCxCheckSelectAll;
Property CheckListBox : TcxCheckListBox read fCxCheckList write fCxCheckList;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DX RnD Components', [TDXCheckListBox]);
end;
{ TDxChecklistGroupBox }
constructor TDXCheckListBox.Create(AOwner: TComponent);
const
CAPTION_HEIGHT = 24;
BUTTON_WIDTH = 24;
begin
inherited;
Parent := TWinControl(AOwner);
SetBounds(Left, Top, 140, 120);
Height := 200;
Width := 200;
fGBSelectAll := TcxGroupBox.Create(self);
fGBSelectAll.Parent := self;
fGBSelectAll.SetBounds(1, 1, 200, 199);
fGBSelectAll.Align := Alclient;
fGBSelectAll.Alignment := alTopLeft;
Fcaption := '';
bevelouter := Bvnone;
fCxCheckSelectAll := TcxCheckListBox.Create(Self);
fCxCheckSelectAll.SetSubComponent(True);
fCxCheckSelectAll.Parent := fGBSelectAll;
fCxCheckSelectAll.Name := 'CxCheckSelectAll';
FdxBevel := TShape.Create(Self);
FdxBevel.Parent := fGBSelectAll;
FgbCheckList := TcxGroupBox.Create(Self);
FgbCheckList.Parent := fGBSelectAll;
fCxCheckList := TcxCheckListBox.Create(Self);
fCxCheckList.SetSubComponent(True);
fCxCheckList.Parent := FgbCheckList;
fcxchecklist.Name := 'cxchecklist';
with fGBSelectAll do
begin
AlignWithMargins := True;
PanelStyle.Active := True;
ParentBackground := False;
ParentColor := False;
Style.BorderColor := 15065047;
Style.BorderStyle := ebsSingle;
Style.Color := clWhite;
Style.LookAndFeel.NativeStyle := False;
TabOrder := 0;
Width := 199;
end;
with fDxBevel do
begin
Left := 0;
Top := 35;
Width := 300;
Height := 1;
Align := alTop;
Pen.Color := 15065047;
end;
with fGBCheckList do
begin
Left := 30;
Top := 39;
Align := alClient;
PanelStyle.Active := True;
ParentBackground := False;
Style.BorderStyle := ebsNone;
Style.LookAndFeel.NativeStyle := False;
StyleDisabled.LookAndFeel.NativeStyle := False;
TabOrder := 0;
Height := 200;
Width := 200;
end;
with fCxCheckList do
begin
Left := 2;
Top := 2;
Width := 200;
Height := 117;
AlignWithMargins := True;
Margins.Left := 5;
Margins.Top := 0;
Margins.Right := 0;
Margins.Bottom := 0;
Align := alClient;
ParentFont := False;
Style.LookAndFeel.ScrollbarMode := sbmTouch;
Style.LookAndFeel.Kind := lfOffice11;
Style.BorderStyle := cbsNone;
Style.Color := clWhite;
Style.Font.Charset := ANSI_CHARSET;
Style.Font.Color := 7697781;
Style.Font.Height := -16;
Style.Font.Name := 'Noto Sans';
Style.Font.Style := [];
Style.HotTrack := True;
Style.LookAndFeel.NativeStyle := False;
StyleFocused.BorderStyle := cbsNone;
StyleHot.BorderStyle := cbsNone;
TabOrder := 0;
showchecks := True;
OnDrawItem := OnDrawCheckList;
OnClickCheck := CheckListBoxCheckClick;
end;
with fCxCheckSelectAll do
begin
AlignWithMargins := True;
Left := 5;
Top := 1;
Width := 200;
Height := 25;//30
Align := alTop;
ParentFont := False;
Margins.Left := 5;
Style.BorderStyle := cbsNone;
Style.BorderColor := 15065047;
Style.Font.Charset := ANSI_CHARSET;
Style.Font.Color := 7697781;
Style.Font.Height := -16;
Style.Font.Name := 'Noto Sans';
Style.Font.Style := [];
Style.LookAndFeel.NativeStyle := False;
StyleDisabled.BorderStyle :=cbsNone;
StyleHot.BorderStyle := cbsNone;
StyleFocused.BorderStyle := cbsNone;
TabOrder := 1;
Caption := '';
showchecks := true;
OnDrawItem := OnDrawCheckList;
OnClickCheck := CheckListBoxAllCheckClick;;
end;
end;
procedure TDXCheckListBox.CheckListBoxAllCheckClick(ASender: TObject; AIndex: Integer; APrevCheckState, ANewCheckState: TcxCheckBoxState);
var
i : integer;
begin
if Assigned(CheckListHeader.OnClickCheck) then
CheckListBoxAllCheckClick(ASender, AIndex, APrevCheckState, ANewCheckState);
for I := 0 to fCxCheckList.Items.Count-1 do
begin
fCxCheckList.Items[i].State := ANewCheckState;
end;
inherited;
end;
procedure TDXCheckListBox.CheckListBoxCheckClick(ASender: TObject; AIndex: Integer; APrevCheckState, ANewCheckState: TcxCheckBoxState);
var
count,I : integer;
begin
if Assigned(CheckListBox.OnClickCheck) then
CheckListBoxCheckClick(ASender, AIndex, APrevCheckState, ANewCheckState);
count := 0;
for I := 0 to fCxCheckList.Items.Count-1 do
begin
if fCxCheckList.Items[i].state = ANewCheckState then
inc(count);
end;
if count = fCxCheckList.Items.Count then
begin
fCxCheckSelectAll.Items[0].state := cbschecked;
end
else
begin
fCxCheckSelectAll.Items[0].state := cbsunchecked;
end;
inherited;
end;
procedure TDXCheckListBox.OnDrawCheckList(AControl: TWinControl; AIndex: Integer; ARect: TRect; AState: TOwnerDrawState);
var
Aflags: Longint;
aCanvas: TcxCanvas;
aChecklistbox: TCxChecklistbox;
aText: string;
begin
Aflags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
aChecklistbox := (AControl as TCxChecklistbox);
aCanvas := aChecklistbox.InnerCheckListBox.Canvas;
aText := aChecklistbox.Items[AIndex].Text;
aCanvas.Brush.Color := clwhite;
aCanvas.FillRect(ARect);
aCanvas.font.Color := aChecklistbox.Style.Font.Color;
aCanvas.font.size := aChecklistbox.Style.Font.size;
aCanvas.font.name := aChecklistbox.Style.Font.name;
ARect.Left := ARect.Left + 3;
DrawText(aCanvas.Handle, PChar(aText), Length(aText), ARect, Aflags);
end;
end.
谢谢。