查到一个例子,大家看看:
procedure TMainForm.btnCustomColorClick(Sender: TObject);
var
cbColor: TdxBarColorCombo;
begin
cbColor := TdxBarColorCombo(TdxBarButton(Sender).Tag);
with TColorDialog.Create(Self) do
begin
Color := cbColor.Color;
if Execute then
cbColor.Color := Color;
Free;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
var
cbColor: TdxBarColorCombo;
btnCustomColor: TdxBarButton;
begin
cbColor := TdxBarColorCombo.Create(Self);
with cbColor do
begin
Caption := 'Color:';
Color := clAqua;
end;
btnCustomColor := TdxBarButton.Create(Self);
with btnCustomColor do
begin
Caption := '...';
Hint := 'Click to select custom color';
PaintStyle := psCaption;
Tag := Integer(cbColor);
OnClick := btnCustomColorClick;
end;
// Adds an item to a sub menu
siFormat.ItemLinks.Add.Item := cbColor;
// Adds an item to a toolbar
with dxBarManager.Bars[2], ItemLinks do
begin
LockUpdate := True;
with Add do
begin
Item := cbColor;
Index := 0;
BringToTopInRecentList;
end;
with Add do
begin
Item := btnCustomColor;
Index := 1;
BringToTopInRecentList;
end;
LockUpdate := False;
end;
end;
这样是可以动态生成的,关键要用到ItemLinks来关联