if (key = 38) and (ComboBox1.ItemIndex = 0)then//key=38是按向上键
     ComboBox1.ItemIndex := ComboBox1.Items.Count-1;
  if (key = 40) and (ComboBox1.ItemIndex = ComboBox1.Items.Count-1)then
//key=40是按向下键
     ComboBox1.ItemIndex := 0; 
我在ComboBox1的keydown中实现

解决方案 »

  1.   

    procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (key = 38) and (ComboBox1.ItemIndex = 0)then//key=38是按向上键
      begin
         ComboBox1.ItemIndex := ComboBox1.Items.Count-1;
         Key := 0;
      end;
      if (key = 40) and (ComboBox1.ItemIndex = ComboBox1.Items.Count-1)then
      begin  //key=40是按向下键
        ComboBox1.ItemIndex := 0;
        Key := 0;
      end;
    end;
      

  2.   

    //最好用命名常量代替数字常量
    procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if (Key = VK_UP) and (ComboBox1.ItemIndex = 0)then//VK_UP是按向上键
      begin
         ComboBox1.ItemIndex := ComboBox1.Items.Count-1;
         Key := 0;
      end;
      if (Key = VK_DOWN) and (ComboBox1.ItemIndex = ComboBox1.Items.Count-1)then
      begin  //VK_DOWN是按向下键
        ComboBox1.ItemIndex := 0;
        Key := 0;
      end;
    end;
      

  3.   

    你這樣不是很好, 還要加個if (key = 38) and (ComboBox1.ItemIndex = 0)then//key=38是按向上键
    begin
         ComboBox1.ItemIndex := ComboBox1.Items.Count-1;
         Key := 0;
    end下面的也是
      

  4.   

    procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if(Key=VK_DOWN)and (ComboBox1.ItemIndex = ComboBox1.Items.Count-1) then
      begin
        ComboBox1.ItemIndex:=0;
        Key:=0;
      end
      else if (key =VK_UP) and (ComboBox1.ItemIndex = 0)then
      begin
         ComboBox1.ItemIndex := ComboBox1.Items.Count-1;
         Key:=0;
      end;end;通过,结帖吧~~收分啦~~^_^