2017-08-17 63 views

回答

3

您需要從列表中刪除的顏色在:

procedure TForm7.FormCreate(Sender: TObject); 
var i: Integer; 
begin 
    i := ColorBox1.Items.IndexOf('clGreen'); 
    if i <> -1 then 
    ColorBox1.Items.Delete(i) 
    else 
    Showmessage('invalid color'); 
end; 
5

的預充的人可以從Items集合中刪除。例如:

procedure TForm31.Button1Click(Sender: TObject); 
var 
    Index: Integer; 
begin 
    Index := ColorBox1.Items.IndexOfObject(TObject(clGreen)); 
    if Index <> -1 then 
    ColorBox1.Items.Delete(Index); 
end; 
+0

我想OP在問IDE怎麼做 –

+1

@Nasreddine,試着在設計的時候把這個組合列表下載:) – Victoria

+0

LOL。確實如此,但這是OP所要求的。我認爲如果你補充說它不能在對象檢查器上完成,並且他需要通過代碼來完成它會更好 –

3

你的問題標題:

如何防止特定顏色的選擇中組件TColorBox?

所以防止不刪除,你有兩個選擇:

  • 防止選擇:

    procedure TForm1.FormCreate(Sender: TObject); 
    begin 
        ColorBox1.ItemIndex := -1; 
    end; 
    
    procedure TForm1.ColorBox1Change(Sender: TObject); 
    begin 
    if ColorBox1.Colors[ColorBox1.ItemIndex] = clNavy then //Choose any color 
        begin 
        ShowMessage('Invalid color'); 
        ColorBox1.ItemIndex := -1; 
        end; 
    end; 
    
  • 如果您需要刪除Color那麼你有兩個答案做那。

+0

刪除是最好的預防:) P.S.身體說 - 「如何去除某種顏色」_。 – Victoria

+0

@維多利亞正如我所說_如果你需要刪除_ :),他知道他想要什麼。 – Sami

相關問題