TcxButtonEdit TcxButtonEdit 编辑框,多按钮 区分触发事件 并伪装成自带下拉框;用到SetCapture(Handle)

//-TcxButtonEdit 编辑框,多按钮 区分触发事件 并伪装成自带下拉框

主要是在 Properties.Buttons 设定多个按钮, btn7PropertiesButtonClick中用AButtonIndex即可区分那个按钮的触发了。
    btn7: TcxButtonEdit;
    lst3: TListBox;
object btn7: TcxButtonEdit
  Left = 520
  Top = 264
  ParentShowHint = False
  Properties.Buttons = <
    item
      Default = True
      Glyph.Data = {
       图片内容}
      Kind = bkGlyph
    end
    item
      LeftAlignment = True
      Stretchable = False
    end
    item
      Caption = #36710#36742
      Kind = bkText
      LeftAlignment = True
      Width = 40
    end>
  Properties.OnButtonClick = btn7PropertiesButtonClick
  ShowHint = True
  TabOrder = 40
  Text = 'btn7'
  Width = 186
end

procedure TForm1.FormCreate(Sender: TObject);
begin
  lst3.Top :=btn7.Top + btn7.Height-2 ;
  lst3.Left :=btn7.Left+1;
  lst3.Visible :=False;
end;

procedure TForm1.btn7PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if AButtonIndex =0  then
  begin
    ShowMessage('查询这台车'+btn7.Text);
  end
  else if (AButtonIndex =1)  then
  begin
    if lst3.Visible then
      lst3.Visible :=False
    else
    begin
      lst3.Visible :=True;
      SetCapture(lst3.Handle) //下拉时 设定其获得其他的捕获,模拟完美下拉框
    end;
  end
  else if (AButtonIndex =2) then //第三个按钮 设定为文字无需动作
  begin
     //
  end;
end;

procedure TForm1.lst3Click(Sender: TObject);
begin
  ReleaseCapture; //释放捕获
  if(lst3.ItemIndex>=0) then
  begin
    btn7.Properties.Buttons[2].Caption :=lst3.Items[lst3.ItemIndex];
    //ShowMessage('取值');
    lst3.Visible :=False;
  end
  else
  begin
    lst3.Visible :=False;
  end;
end;

上图的 123 指 AButtonIndex 的值分别为 0 1 2;

posted @ 2016-08-19 10:31  海蓝7  阅读(668)  评论(0编辑  收藏  举报