📄 jvshapetypecombobox.pas
字号:
if W < H then
S := W
else
S := H;
Rectangle(Rect(X, Y, X + W, Y + H));
end;
end;
var
aColor: TColor;
begin
with Canvas do begin
aColor := Brush.Color;
Brush.Color := Color;
FillRect(R);
Brush.Style:=bsSolid;
Brush.Color:=clGray;
OffsetRect(R,2,2);
DrawShape(R);
OffsetRect(R,-2,-2);
Brush.Style:=bsSolid;
Brush.Color:=$00f0caa6;
DrawShape(R);
Brush.Style:=GetEnumValue(Items[Index]);;
if Brush.Style=bsClear then
Brush.Color:=$00f0caa6
else
Brush.Color:=clYellow;
DrawShape(R);
R.Left := R.Left + 28 + 6;
R.Right := R.Left + TextWidth(Items[Index]) + 6;
Brush.Color := aColor;
Brush.Style:=bsSolid;
FillRect(R);
OffsetRect(R, 2, 0);
DrawText(Canvas.Handle, PChar(Items[Index]), -1, R, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
OffsetRect(R, -2, 0);
if odSelected in State then
DrawFocusRect(R);
end;
end;
function TJvBrushStyleComboBox.GetBrushStyle:TBrushStyle;
begin
result:=GetEnumValue(text);
end;
procedure TJvBrushStyleComboBox.SetBrushStyle(value:TBrushStyle);
begin
ItemIndex:=Items.IndexOf(GetEnumName(Value));
end;
{TPenStyleComboBox}
constructor TJvPenStyleComboBox.Create(AOwner:TComponent);
begin
inherited create(AOwner);
FHiliteColor := clHighLight;
FHiLiteText := clHighLightText;
Style := csOwnerDrawFixed;
if not (csDesigning in ComponentState) then
GetPenStyles
else
Text:='psSolid';
end;
procedure TJvPenStyleComboBox.GetPenStyles;
var
i:integer;
begin
Clear;
with Items do begin
for i:=low(PenNames) to High(PenNames) do begin
Add(PenNames[i]);
end;
end;
ItemIndex:=0;
end;
function TJvPenStyleComboBox.GetEnumName(AStyle:TPenStyle):string;
begin
result:=PenNames[Integer(AStyle)];
end;
function TJvPenStyleComboBox.GetEnumValue(AName:String):TPenStyle;
var
i:integer;
begin
for i:=low(PenNames) to High(PenNames) do begin
if PenNames[i]=AName then break;
end;
if i<=High(PenNames) then
result:=PenValues[i]
else
result:=psSolid;
end;
procedure TJvPenStyleComboBox.CNDrawItem(var Message: TWMDrawItem);
var
State: TOwnerDrawState;
begin
with Message.DrawItemStruct^ do
begin
State := [];
if bool(itemState and ODS_CHECKED) then
Include(State, odChecked);
if bool(itemState and ODS_COMBOBOXEDIT) then
Include(State, odComboBoxEdit);
if bool(itemState and ODS_DEFAULT) then
Include(State, odDefault);
if bool(itemState and ODS_DISABLED) then
Include(State, odDisabled);
if bool(itemState and ODS_FOCUS) then
Include(State, odFocused);
if bool(itemState and ODS_GRAYED) then
Include(State, odGrayed);
if bool(itemState and ODS_SELECTED) then
Include(State, odSelected);
Canvas.Handle := hDC;
Canvas.Font := Font;
Canvas.Brush := Brush;
if (Integer(itemID) >= 0) and (odSelected in State) then
begin
Canvas.Brush.Color := FHiliteColor;
Canvas.Font.Color := FHiliteText;
end;
if Integer(itemID) >= 0 then
DrawItem(itemID, rcItem, State)
else
Canvas.FillRect(rcItem);
Canvas.Handle := 0;
end;
end;
procedure TJvPenStyleComboBox.DrawItem(Index: Integer; R: TRect; State: TOwnerDrawState);
procedure DrawShape(r:TRect;bLine:boolean);
var
x,y,w,h,s:integer;
begin
with Canvas do begin
X := R.Left+2;
Y := R.top+2;
W := 28 - Pen.Width + 1;
H := R.Bottom-R.Top-4 - Pen.Width + 1;
if Pen.Width = 0 then begin
Dec(W);
Dec(H);
end;
if W < H then
S := W
else
S := H;
if bLine then begin
MoveTo(x+1,y+h div 2);
LineTo(x+w-1,y+h div 2);
end
else
Rectangle(Rect(X, Y, X + W, Y + H));
end;
end;
var
aColor: TColor;
begin
with Canvas do begin
aColor := Brush.Color;
Brush.Color := Color;
FillRect(R);
Brush.Color:=clGray;
OffsetRect(R,2,2);
DrawShape(R,false);
OffsetRect(R,-2,-2);
Brush.Color:=$00f0caa6;
DrawShape(R,false);
Pen.Color:=clYellow;
Pen.Style:=GetEnumValue(Items[Index]);
DrawShape(R,True);
Pen.Color:=clBlack;
Pen.Style:=psSolid;
R.Left := R.Left + 28 + 6;
R.Right := R.Left + TextWidth(Items[Index]) + 6;
Brush.Color := aColor;
FillRect(R);
OffsetRect(R, 2, 0);
DrawText(Canvas.Handle, PChar(Items[Index]), -1, R, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
OffsetRect(R, -2, 0);
if odSelected in State then
DrawFocusRect(R);
end;
end;
function TJvPenStyleComboBox.GetPenStyle:TPenStyle;
begin
result:=GetEnumValue(text);
end;
procedure TJvPenStyleComboBox.SetPenStyle(value:TPenStyle);
begin
ItemIndex:=Items.IndexOf(GetEnumName(Value));
end;
{TPenWidthComboBox}
constructor TJvPenWidthComboBox.Create(AOwner:TComponent);
begin
inherited create(AOwner);
FHiliteColor := clHighLight;
FHiLiteText := clHighLightText;
Style := csOwnerDrawFixed;
if not (csDesigning in ComponentState) then
GetPenWidths
else
Text:='1';
end;
procedure TJvPenWidthComboBox.GetPenWidths;
var
i:integer;
begin
Clear;
with Items do begin
for i:=1 to 5 do begin
Add(IntToStr(i));
end;
end;
ItemIndex:=0;
end;
function TJvPenWidthComboBox.GetEnumName(AStyle:integer):string;
begin
result:=IntToStr(AStyle);
end;
function TJvPenWidthComboBox.GetEnumValue(AName:String):Integer;
begin
result:=StrToInt(AName);
end;
procedure TJvPenWidthComboBox.CNDrawItem(var Message: TWMDrawItem);
var
State: TOwnerDrawState;
begin
with Message.DrawItemStruct^ do
begin
State := [];
if bool(itemState and ODS_CHECKED) then
Include(State, odChecked);
if bool(itemState and ODS_COMBOBOXEDIT) then
Include(State, odComboBoxEdit);
if bool(itemState and ODS_DEFAULT) then
Include(State, odDefault);
if bool(itemState and ODS_DISABLED) then
Include(State, odDisabled);
if bool(itemState and ODS_FOCUS) then
Include(State, odFocused);
if bool(itemState and ODS_GRAYED) then
Include(State, odGrayed);
if bool(itemState and ODS_SELECTED) then
Include(State, odSelected);
Canvas.Handle := hDC;
Canvas.Font := Font;
Canvas.Brush := Brush;
if (Integer(itemID) >= 0) and (odSelected in State) then
begin
Canvas.Brush.Color := FHiliteColor;
Canvas.Font.Color := FHiliteText;
end;
if Integer(itemID) >= 0 then
DrawItem(itemID, rcItem, State)
else
Canvas.FillRect(rcItem);
Canvas.Handle := 0;
end;
end;
procedure TJvPenWidthComboBox.DrawItem(Index: Integer; R: TRect; State: TOwnerDrawState);
procedure DrawShape(r:TRect;bLine:boolean);
var
x,y,w,h,s:integer;
begin
with Canvas do begin
X := R.Left+2;
Y := R.top+2;
W := 28 - Pen.Width + 1;
H := R.Bottom-R.Top-4 - Pen.Width + 1;
if Pen.Width = 0 then begin
Dec(W);
Dec(H);
end;
if W < H then
S := W
else
S := H;
if bLine then begin
MoveTo(x+1,y+h div 2);
LineTo(x+w-1,y+h div 2);
end
else
Rectangle(Rect(X, Y, X + W, Y + H));
end;
end;
var
aColor: TColor;
begin
with Canvas do begin
aColor := Brush.Color;
Brush.Color := Color;
FillRect(R);
Brush.Color:=clGray;
OffsetRect(R,2,2);
DrawShape(R,false);
OffsetRect(R,-2,-2);
Brush.Color:=$00f0caa6;
DrawShape(R,false);
Pen.Color:=clYellow;
Pen.Style:=psSolid;
Pen.Width:=GetEnumValue(Items[Index]);
DrawShape(R,True);
Pen.Color:=clBlack;
Pen.Style:=psSolid;
Pen.Width:=1;
R.Left := R.Left + 28 + 6;
R.Right := R.Left + TextWidth(Items[Index]) + 6;
Brush.Color := aColor;
FillRect(R);
OffsetRect(R, 2, 0);
DrawText(Canvas.Handle, PChar(Items[Index]), -1, R, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
OffsetRect(R, -2, 0);
if odSelected in State then
DrawFocusRect(R);
end;
end;
function TJvPenWidthComboBox.GetPenWidth:integer;
begin
if Text='' then
result:=1
else
result:=StrToInt(text);
end;
procedure TJvPenWidthComboBox.SetPenWidth(value:Integer);
begin
ItemIndex:=Items.IndexOf(IntToStr(Value));
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -