當我從另一個控件選項卡切換到組合框時,它會在文本週圍顯示帶虛線的框,但是當我將控件設置爲以編程方式激活時, t顯示相同的重點指標。vcl combobox並不總是顯示它有焦點
是否有解決此問題的方法?
我有德爾福XE6
MCVE
unit Unit27;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TForm27 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form27: TForm27;
implementation
{$R *.dfm}
procedure TForm27.Button1Click(Sender: TObject);
begin
ComboBox1.SetFocus;
end;
end.
object Form27: TForm27
Left = 0
Top = 0
Caption = 'Form27'
ClientHeight = 90
ClientWidth = 246
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 16
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Button1: TButton
Left = 152
Top = 8
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object ComboBox1: TComboBox
Left = 16
Top = 39
Width = 145
Height = 21
Style = csDropDownList
ItemIndex = 2
TabOrder = 2
Text = '2'
Items.Strings = (
'0'
'1'
'2'
'3')
end
end
開始應用,並Button1
左鍵單擊,它調用
ComboBox1.SetFocus;
請注意,沒有繪製焦點矩形,但組合具有焦點,如下所示: 向上或向下箭頭鍵盤上的箭頭。組合項目更改,現在焦點矩形變爲可見。 聚焦矩形顯示一次後,鼠標在Button1上單擊後也會繪製在組合上。因此,重複這個問題,重新啓動應用程序。
請顯示[mcve] –
「當我將控件設置爲以編程方式激活時」確切地說,您是如何做到這一點的?我們可以看到你的代碼嗎? –
'ComboBox.SetFocus;'? – Johan