【发布时间】:2016-03-22 12:14:12
【问题描述】:
当我从另一个控件切换到组合框时,它会在文本周围显示带有虚线的框,但是当我以编程方式将控件设置为活动时,它不会显示相同的焦点指示器。
这种行为有解决办法吗?
我有 Delphi 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 后,它也会绘制在组合上。因此,要重复该问题,请重新启动应用程序。
【问题讨论】:
-
“当我以编程方式将控件设置为活动时” 你到底是怎么做的?我们可以看看你的代码吗?
-
ComboBox.SetFocus;? -
如果您使用键盘加速器,则会绘制焦点矩形。这就是操作系统的工作原理。
-
运行记事本,打开文件,点击tab一次,文档类型按钮有焦点矩形。关闭对话框,再次打开文件,用鼠标点击文件类型组合,没有绘制焦点矩形。
标签: delphi