界面库

listbox添加checkbox
This commit is contained in:
JianjunLiu 2022-10-25 12:09:40 +08:00
parent b26de5f0fc
commit 80977eb23d
2 changed files with 37 additions and 9 deletions

View File

@ -2237,7 +2237,7 @@ type TListBox = class(TcustomListBox)
return array("name","caption","anchors","align","enabled",
"font","visible","border","color",
"height","width","left","top","items",
"multisel","popupmenu","wsdlgmodalframe",
"multisel","checkbox","popupmenu","wsdlgmodalframe",
"onmousedown","onmouseup",
"onselectionchange"
);

View File

@ -3134,6 +3134,7 @@ type TcustomListBox=class(TCustomListBoxbase)
FSelBegin :=-1;
FSelEnd :=-1;
FMultisel := false;
fcheckbox := false;
end
function MouseUp(o,e);override;
begin
@ -3233,8 +3234,19 @@ type TcustomListBox=class(TCustomListBoxbase)
@param(rc)(array) »æÖÆÇøÓò%%
@param(cvs)(tcustomcanvas) »­²¼ %%
**}
PaintIdxBkg(idx,rc,cvs);
PaintIdexText(idx,rc,cvs);
r := PaintIdxBkg(idx,rc,cvs);
rc1 := rc;
if fcheckbox then
begin
h := rc[3]-rc[1];
nh := min(h,16);
nnh := integer((h-nh)/2);
rc2 := array(rc[0]+2,rc[1]+nnh,rc[0]+nh+2,rc[3]-nnh);
cvs.Draw("framecontrol",array(rc2[0:1],rc2[2:3]),DFC_BUTTON,(r)?DFCS_CHECKED:DFCS_BUTTONCHECK);
rc1[0]+=nh+5;
end
PaintIdexText(idx,rc1,cvs);
end
function PaintIdexText(idx,rc,cvs);virtual;
begin
@ -3331,9 +3343,12 @@ type TcustomListBox=class(TCustomListBoxbase)
@param(state)(bool)״̬%%
**}
b := state?1:0;
if FMultisel <> 2 or not isValidIndex(n)or b=getItemSelectedState(n)then return;
if (FMultisel <> 2) or not(isValidIndex(n)) or (b=getItemSelectedState(n)) then return;
if b then FMultisel3Data[n]:= b;
else reindex(FMultisel3Data,array(n:nil));
else
begin
reindex(FMultisel3Data,array(n:nil));
end
if FselectionChange then
CallMessgeFunction(FselectionChange,self(true),new tuieventbase(0,0,0,0));
InvalidateIdxRect(n);
@ -3562,6 +3577,7 @@ type TcustomListBox=class(TCustomListBoxbase)
end
property ItemCount read GetItemCount;
property Multisel:bool read FMultisel write SetMultisel;
property checkbox:bool read fcheckbox write setcheckbox;
property onSelectionChange:eventhandler read FselectionChange write FselectionChange;
property Items:strings read GetData write setData;
protected
@ -3598,10 +3614,21 @@ type TcustomListBox=class(TCustomListBoxbase)
begin
if(idx >= min(FSelBegin,FSelEnd)and idx <= max(FSelBegin,FSelEnd))or(FMultisel=2 and FMultisel3Data[idx])then
begin
r := true;
cvs.brush.Color := rgb(204,231,255);
end else
cvs.Brush.Color := Color;
cvs.FillRect(rc);
return r;
end
function setcheckbox(c);
begin
nc := c?true:false;
if nc<>fcheckbox then
begin
fcheckbox := nc;
InvalidateRect(nil,false);
end
end
function SetMultisel(n);
begin
@ -3736,6 +3763,7 @@ type TcustomListBox=class(TCustomListBoxbase)
FSelEnd;
FIsMouseDown;
FMultisel;
fcheckbox;
FMultisel3Data;
FFormerSelBegin;
FFormerSelEnd;