可以用 style := cbCustomColors 来去掉首项为自定义颜色框,见源码注释: TColorBoxStyles = (cbStandardColors, // first sixteen RGBI colors cbExtendedColors, // four additional reserved colors cbSystemColors, // system managed/defined colors cbIncludeNone, // include clNone color, must be used with cbSystemColors cbIncludeDefault, // include clDefault color, must be used with cbSystemColors cbCustomColor, // first color is customizable cbPrettyNames, cbCustomColors); // All colors are custom colors
procedure TForm1.SetColorBoxItems(ColorBox : TColorBox);
var
a,b,c:cardinal;
begin
ColorBox.Style:=[cbCustomColor]; a:=clred;
ColorBox.Items.AddObject('浅绿色',TObject(a)); a:=clyellow;
ColorBox.Items.AddObject('黑色',TObject(a));
a:=clBlue;
ColorBox.Items.AddObject('蓝色',TObject(a));end;
按照你的这个代码也可以,问题是style:=cbCustomColor时, 这样生成的下拉框选项中的第一项会有个custom的项,如果选择的话会出来一个自定义颜色的对话框。
可是我不想有这个自定义的颜色啊,我就想让用户只能选择我提供的那几个颜色的选项,要怎么实现呢?谢谢大家!
不用cbCustomColor的话会有其他的好多自动生成的颜色选项啊,我就想让它有红黄蓝三个色。
ColorBox1.Items.Delete(0);后,虽然那custom项没了,但是点击第一项的话还会弹出自定义颜色的那个对话框
TColorBoxStyles = (cbStandardColors, // first sixteen RGBI colors
cbExtendedColors, // four additional reserved colors
cbSystemColors, // system managed/defined colors
cbIncludeNone, // include clNone color, must be used with cbSystemColors
cbIncludeDefault, // include clDefault color, must be used with cbSystemColors
cbCustomColor, // first color is customizable
cbPrettyNames,
cbCustomColors); // All colors are custom colors