c#让一个控件无法获得焦点
展开全部
erEvent(Sender: TObject);
begin
if Sender is TEdit then
TEdit(Sender).Color := clRed
else if Sender is TComboBox then
TComboBox(Sender).Color := clRed;
//这里也可以这样写
//TEdit(Sender).Color := clRed;
//强制转换为TEdit类,TComboBox和TEdit共同的类TWinControl没有Color属性,
//如果规范点就不要这样写,虽然不会出错。下同。
end;
procedure TForm1.EditExitEvent(Sender: TObject);
begin
if Sender is TEdit then
TEdit(Sender).Color := clBlue
else if Sender is TComboBox then
TComboBox(Sender).Color := clBlue;
end;
procedure TForm1.SetEnterExitEvent(aControl: TWinControl);
var
i: integer;
begin
for i:=0 to aControl.ComponentCount-1 do
begin
if aControl.Components[i].ComponentCount > 0 then
SetEnterExitEvent(aControl.Components[i])
else
begin
if (aControl.Components[i] is TEdit) or (aControl.Components[i] is TComboBox) then
begin
TEdit(aControl.Components[i]).OnEnter := EditEnterEvent;
TEdit(aControl.Components[i]).OnExit := EditExitEvent;
TComboBox(aControl.Components[i]).OnEnter := EditEnterEvent;
TComboBox(aControl.Components[i]).OnExit := EditExitEvent;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetEnterExitEvent(Self);
end;
begin
if Sender is TEdit then
TEdit(Sender).Color := clRed
else if Sender is TComboBox then
TComboBox(Sender).Color := clRed;
//这里也可以这样写
//TEdit(Sender).Color := clRed;
//强制转换为TEdit类,TComboBox和TEdit共同的类TWinControl没有Color属性,
//如果规范点就不要这样写,虽然不会出错。下同。
end;
procedure TForm1.EditExitEvent(Sender: TObject);
begin
if Sender is TEdit then
TEdit(Sender).Color := clBlue
else if Sender is TComboBox then
TComboBox(Sender).Color := clBlue;
end;
procedure TForm1.SetEnterExitEvent(aControl: TWinControl);
var
i: integer;
begin
for i:=0 to aControl.ComponentCount-1 do
begin
if aControl.Components[i].ComponentCount > 0 then
SetEnterExitEvent(aControl.Components[i])
else
begin
if (aControl.Components[i] is TEdit) or (aControl.Components[i] is TComboBox) then
begin
TEdit(aControl.Components[i]).OnEnter := EditEnterEvent;
TEdit(aControl.Components[i]).OnExit := EditExitEvent;
TComboBox(aControl.Components[i]).OnEnter := EditEnterEvent;
TComboBox(aControl.Components[i]).OnExit := EditExitEvent;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetEnterExitEvent(Self);
end;
追问
除了Ctrl C Ctrl V还会 别的吗????
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询